Results 1 to 2 of 2

Thread: realloc

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Qt products
    Qt3
    Platforms
    Windows
    Thanks
    53

    Default realloc

    Hello,
    does anyone explain me why the 'realloc' (at the second time) throw a runtime error?

    thanks.
    Attached Files Attached Files
    Regards

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: realloc

    Your error is here:
    Qt Code:
    1. realloc( Val_, sizeof(double) * MC.ValLength_ );
    To copy to clipboard, switch view to plain text mode 

    Realloc can move the memory block to a new mem location when extending, if there is not enough room at the current location. You missed the fact that the new address is returned by realloc. Therefore you should have:

    Qt Code:
    1. Val_ = (double *)realloc( Val_, sizeof(double) * MC.ValLength_ );
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to marcel for this useful post:

    mickey (4th May 2008)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.