Re: sizeof([ALLOCATED MEMORY])



In article <eJ6dnTe9u7iOZMrZnZ2dnUVZ8sydnZ2d@xxxxxx>,
Richard Heathfield <invalid@xxxxxxxxxxxxxxx> wrote:

ballpointpenthief said:

If I have malloc()'ed a pointer and want to read from it as if it were
an array, I need to know that I won't be reading past the last index.

When you allocate the memory, you know precisely how much memory you are
requesting.

Don't Forget (tm).

However when you allocate the memory, you don't know precisely how much
you received. It could be more than you requested. And common
applications exist which could make use of that extra memory if only
they knew it existed (e.g. a dynamic array).

Major OS's provide this functionality in a non-portable fashion. Imho C
should provide a portable layer over this functionality.

-Howard
.



Relevant Pages

  • Re: Another C# marshaling question
    ... // Get the pointer of the location in memory. ... > public static extern int FF_Function( ... > // Allocate the array. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: INTENT(WORKSPACE) as a new Fortran feature?
    ... >> the array once in the caller than each time within the subroutine. ... > the stack pointer is being changed to allocate local variables in any ... "actual" memory would never be touched at all. ... If, on a particular machine, the compiler knows that it would be ...
    (comp.lang.fortran)
  • Re: Storing the size of an array in the structure itself
    ... >> I think every C programmer can relate to the frustrations that malloc ... >> the size of an array must be stored separately to be a nightmare. ... is anything more than just that - a chunk of memory. ... > Otherwise you couldn't tell it how much to allocate. ...
    (comp.lang.c)
  • Re: Creating a logical matrix in a mex-file
    ... Then use mxMalloc to allocate the memory ... Use mxSetData to set the data of the array to the ... This would avoid the initialization of the memory. ...
    (comp.soft-sys.matlab)
  • Re: The problems arrayed before me...
    ... > When an array is grown, how does Delphi manage this cleanly? ... default memory manager, the first thing it tries to do, when it receives ... When you ask for a certain amount of memory, the memory manager is free ... to allocate more than you ask for, and it keeps track of that. ...
    (alt.comp.lang.borland-delphi)