CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 1999
    Location
    UK, London
    Posts
    155

    Realloc Weirdness

    Hi
    I have a byte * (with memory alloc'd) which basically hold the contents of a file after a CFile::Read

    i then want to add more to it...

    but when i go to add more allocated memory
    with realloc

    it doesnt seem to add more memory to that already alloc'd

    code
    --
    earlier
    BYTE * image ;
    etc etc


    size_t imSz = _msize(image);
    // add more memory space
    size_t newSz = imSz + ((newSize - newPartImageStart)*sizeof(BYTE));

    if (realloc(image, newSz) == NULL)
    exit(1);


    imSz = _msize(image);


    what i find here is that imSz hasnt changed a bit!
    which is totally weird...

    does anyone have any ideas

    Regards

    Bryce Burrows


  2. #2
    Join Date
    Apr 1999
    Location
    UK, London
    Posts
    155

    Realloc Weirdness

    Hi
    I have a byte * (with memory alloc'd) which basically hold the contents of a file after a CFile::Read

    i then want to add more to it...

    but when i go to add more allocated memory
    with realloc

    it doesnt seem to add more memory to that already alloc'd

    code
    --
    earlier
    BYTE * image ;
    etc etc


    size_t imSz = _msize(image);
    // add more memory space
    size_t newSz = imSz + ((newSize - newPartImageStart)*sizeof(BYTE));

    if (realloc(image, newSz) == NULL)
    exit(1);


    imSz = _msize(image);


    what i find here is that imSz hasnt changed a bit!
    which is totally weird...

    does anyone have any ideas

    Regards

    Bryce Burrows


  3. #3

    Re: Realloc Weirdness

    why you ignoring return value of realloc? (only testing to null)
    look to help at realloc simple example
    (input value stays allocated when is return value null)
    for more details look into realloc.c (i have it at crt\src directory, you maybe at msvc cd only)


  4. #4
    Join Date
    Apr 1999
    Location
    UK, London
    Posts
    155

    Re: Realloc Weirdness

    *duuuh* i feel soo stupid you are totally correct
    I was looking at the wrong bit
    but its all sorted now...thanks muchly fo ryour help

    *feels like a plonker*
    Regards
    bryce


  5. #5
    Join Date
    Apr 1999
    Location
    UK, London
    Posts
    155

    Re: Realloc Weirdness

    *duuuh* i feel soo stupid you are totally correct
    I was looking at the wrong bit
    but its all sorted now...thanks muchly fo ryour help

    *feels like a plonker*
    Regards
    bryce


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