Peter N Lewis wrote:
I often need to store a lot of strings, and don't want to waste the space allocated to a String(255) for each one. With "short" strings, I just allocate memory (with the Mac system NewPtr routine, not with the Pascal New routine) for Length(s)+1 bytes, and then BlockMove the string in. This has the advantage that the string can be references as just Str255Ptr(s)^ (sometimes the size needs to be aligned to 2 or 4 bytes, depending on the platform).
I could do the same thing with GPC's Schema String(255), but I'd have to pack them in, and then unpack them out to a temporary variable to access them, I could not access them in place in the packed data block.
I presume there are clever ways to do such things in GPC/EP? What would be the options for packing strings into a block of memory and yet still having them usable?
var p: ^String; New (p, ActualLength); simply use p^ E.g.: program Foo (Input, Output); var StaticString: String (2048); { or whatever you like } p: ^String; begin ReadLn (StaticString); New (p, Length (StaticString)); p^ := StaticString; WriteLn (p^) end. No type-casts, hand-made size computations, worries about alignment or other dirty tricks necessary. That's one of the nice things about schemata (of which strings are a special case). Frank -- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/, 7977168E GPC To-Do list, latest features, fixed bugs: http://www.gnu-pascal.de/todo.html GPC download signing key: ACB3 79B2 7EB2 B7A7 EFDE D101 CD02 4C9D 0FE0 E5E8