SA-MP Forums Archive
Storing variable-length strings in a 2D array - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Storing variable-length strings in a 2D array (/showthread.php?tid=448473)



Storing variable-length strings in a 2D array - MP2 - 04.07.2013

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).


Re: Storing variable-length strings in a 2D array - ReVo_ - 04.07.2013

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.


Re: Storing variable-length strings in a 2D array - MP2 - 04.07.2013

Clearly you didn't read my post.


Re: Storing variable-length strings in a 2D array - ReVo_ - 04.07.2013

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


Re: Storing variable-length strings in a 2D array - MP2 - 04.07.2013

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.