[fpc-pascal] New object created in custom pool

Vincent Snijders vsnijders at vodafonevast.nl
Tue Oct 28 11:23:18 CET 2008


JoshyFun schreef:
> Hello FPC-Pascal,
> 
> My application will create thousands of small objects of the same
> class, this objects are not created or destroyed in a row, so memory
> fragmentation could becomes a serious problem after some time.
> 
> My question is: Is there any way to override the object creation to
> use a specific memory block ? This means, I plan to get a quite big
> bunch of continuos memory block at the beginning to allocate the
> needed space for all objects of that specific class and assign slots
> "manually" and reduce the memory fragmentation.
> 
> In other words, is there any way to write something like overriding the
> create method like:
> 
> constructor MyObject.Create()
> begin
>      result:=GetMem(sizeof(myobject));
> end;

You can override class function TObject.NewInstance : tobject;

For allocating the memory, you could use a special memory manager from pooledmm:
http://lazarus-ccr.sourceforge.net/docs/fcl/pooledmm/index-4.html

Vincent



More information about the fpc-pascal mailing list