How would I optimize this parser?
bearophile
bearophileHUGS at lycos.com
Mon Nov 1 05:12:18 PDT 2010
spir:
> Then an optimization would be to somehow grossly predict array sizes and preallocate?
In some situations that's not handy to do, because you don't know what's a good size to preallocate. So I suggest a more general solution, to create a struct that inside keeps a dynamic array of pointers to fixed-sized chunks of structs. The size of the chunk size is chosen at compile time to be "good" (close to 64 KB, for example). A member function of this struct may return a pointer to a new struct on request, and allocate a new chunk when the last allocated chunk is full. Another member function may clear the data structure with no deallocation (just resetting the pointer to the first free struct), and another member function may really free all the chunks. This data structure may allocate its chunks from the GC heap or the C heap. This is the data structure I have used for this parser.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list