Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2012-10

cmem Size Field

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ewald

Hello,

In the cmem unit I see that there is always some extra room allocated where the size in bytes of the requested memory block is stored. Also I noticted that this size is never really used.

While I do see the point of the field (e.g. checking for right size parameter in FreeMemSize or some other debugging functionality), I do not see why this extra memory is needed always since the calls in the C library (malloc, free, realloc, calloc) do not need this kind of information.

Am I missing something here is this a bit of left-over code?

Ewald

Reply by email

Jonas Maebe
Ewald wrote 9 lines
In the cmem unit I see that there is always some extra room allocated where the size in bytes of the requested memory block is stored. Also I noticted that this size is never really used. While I do see the point of the field (e.g. checking for right size parameter in FreeMemSize or some other debugging functionality), I do not see why this extra memory is needed always since the calls in the C library (malloc, free, realloc, calloc) do not need this kind of information.

As you explain, the FPC heap manager is what requires this information. The MemSize function is standard functionality of the FPC heap managers, and so is checking whether the correct size is specified when calling freemem(p,size).

Jonas

Reply by email

Ewald
to Jonas Maebe

I see... On the other hand, documentation
(http://www.freepascal.org/docs-html/prog/progsu160.html) says that MemSize() should return the total amount of memory available for allocation; and can return 0 in case this functionality is not supported.

In contrast, the RTL docs postulate that MemSize() should return the size of a previous allocated memory chunk. Which is what I always thought that MemSize() did. This functionality is however not mentioned in the documentation on the memory manager (see the above link)...

Am I missing something here?

Thanks in advance,
Ewald

On Fri, 19 Oct 2012 10:43:43 +0200, Jonas Maebe

Show quoted text 5 lines
As you explain, the FPC heap manager is what requires this information. The MemSize function is standard functionality of the FPC heap managers, and so is checking whether the correct size is specified when calling freemem(p,size).

Reply by email

Jonas Maebe
to Ewald
Ewald wrote 16 lines
On Fri, 19 Oct 2012 10:43:43 +0200, Jonas Maebe wrote: > > As you explain, the FPC heap manager is what requires this > information. > The MemSize function is standard functionality of the FPC heap > managers, > and so is checking whether the correct size is specified when calling > freemem(p,size). I see... On the other hand, documentation (http://www.freepascal.org/docs-html/prog/progsu160.html) says that MemSize() should return the total amount of memory available for allocation; and can return 0 in case this functionality is not supported.

It's probably a copy/paste error from the documentation for memavail, please file a bug report. Thanks.

Show quoted text 5 lines
In contrast, the RTL docs postulate that MemSize() should return the size of a previous allocated memory chunk. Which is what I always thought that MemSize() did.

Indeed.

Jonas

Reply by email

Ewald
to Jonas Maebe

Thanks, I just filed the bug: id 23165.

Ewald On 10/19/12 16:11, Jonas Maebe wrote: >> I see... On the other hand, documentation >> (http://www.freepascal.org/docs-html/prog/progsu160.html) says that >> MemSize() should return the total amount of memory available for >> allocation; and can return 0 in case this functionality is not >> supported. > > It's probably a copy/paste error from the documentation for memavail, > please file a bug report. Thanks. > >> In contrast, the RTL docs postulate that MemSize() should return the >> size >> of a previous allocated memory chunk. Which is what I always thought >> that >> MemSize() did. > > Indeed.

Reply by email