[fpc-pascal] question about FPC heap and threading

Seth Grover sethdgrover at gmail.com
Wed Aug 11 23:35:49 CEST 2010


These are very simple questions, but I just want to make sure a few of
my assumptions are correct:

1. The default FPC heap manager uses one heap per thread, right? I am
basing this assumption off of things I have read in various threads on
this and other mailing lists since around 2.2.x-ish. Looking at
heap.inc I see that the "freelists" variable is a threadvar, which
indicates to me that each thread has its own heap.

2. When a thread is started via, for example, BeginThread
(http://www.freepascal.org/docs-html/rtl/system/beginthread.html) this
heap, as well as all other threadvars in my code and the rtl code, is
setup and initialized automatically, correct?

3. When this thread exits (in the example of using BeginThread, when
the TThreadFunc function passed in to BeginThread terminates) the heap
for that thread, in addition to the other threadvars, are
automatically disposed, correct?

The reason I ask is that I have a program (which executes a lot of
worker threads via BeginThread) which is experiencing increasing
memory usage. heaptrc does not indicate that there are any leaks, but
it's a fairly complex program (we have some units where we're getting
memory from libc directly, don't ask) so I'm not even supposing at
this point that the increasing memory belongs to the FPC heaps at all,
but I'm just trying to make sure I understand everything that's going
on before I go making assumptions about where the memory allocation is
coming from.

Thanks,

-SG

--
This email is fiction. Any resemblance to actual events
or persons living or dead is purely coincidental.

Seth Grover
sethdgrover[at]gmail[dot]com



More information about the fpc-pascal mailing list