CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: _msize()

  1. #1
    Join Date
    May 1999
    Location
    Croatia, Europe
    Posts
    7

    _msize()

    I noticed really weird bug in VC (6.0 SP2).

    void *aa=malloc(0);
    long bb=_msize(aa);

    In Debug Build, _msize returns correct value - 0, but in Release Build, 12 is returned!

    I don't think this is correct behaviour, and, AFAIR, _msize() functioned just fine until two weeks ago. Where is the problem?


    - Goran.

  2. #2
    Join Date
    Apr 1999
    Posts
    32

    Re: _msize()

    _msize
    Returns the size of a memory block allocated in the heap.

    malloc(size)
    The malloc function allocates a memory block of at least size bytes. The block may be larger than size bytes because of space required for alignment and maintenance information.

    So, as you can see, malloc might actually allocate a block size that's larger than the amount you requested. When this happens you are free to use the whole allocated block, and _msize is twlling you how much space you actually have. So even though you allocated 0 byes, you have been given 12 bytes and may use all those 12 bytes if you wish.



    --
    Daren Chandisingh

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured