Storing variable-length strings in a 2D array
#1

Okay, so I need a 2D array (well 3D I guess because they're strings) that can store variable length strings (literally from 1 character to thousands).

pawn Код:
new SomeArray[][][] = {
{
"short",
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"
}
};
The problem is, PAWN doesn't support this. The size of the array is set as the longest string, which would be thousands of cells, and the majority of strings will be under 144 chars. Any recommendations? I looked at malloc by ******, but not sure if that's exactly what I'm looking for (for 3D arrays).
Reply
#2

Wait, you are working with 2d
something like

Код:
{ {0,0}, {1,1} }
This should compile:
Код:
new Strings[][][] =
{
	{
		{"Hello", "Omfg"}
 	},
	{
		{"World", "Omfg"}
	}
};
and should do what you want.
Reply
#3

Clearly you didn't read my post.
Reply
#4

Your problem is the size of the cell? You want to allocate the size in a dynamic way?
Reply
#5

Yes. Some messages will be thousands of cells big. I don't want all 50,000 strings to be 4000 cells long when most of them are going to be < 128.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)