4 ms·
If strings are immutable in L0x then this string representation: struct sObjString { Obj obj; int length; char* chars;
by c-smile 8y ago
If strings are immutable in L0x then this string representation:
struct sObjString {
Obj obj;
int length;
char* chars;
};
needlessly wastes 4 or 8 bytes for the chars pointer (among other heap management overhead related to separate allocations).
Instead, I think, you should have
struct sObjString {
Obj obj;
int length;
char chars[0];
};
and allocate that string object as one chunk with its characters.
- munificent 8y agoTake a look at the first challenge exercise at the end of the chapter. :)
- c-smile 8y agoMy pardon, hadn't got to that part at the moment of commenting.