CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    1

    Using Realloc with the result of New?

    I've just come upon something that I had never thought of before: can realloc() be used on a ptr that was assigned by the new opperator? And if so, will the opperator delete function correctly?


  2. #2
    Join Date
    Jul 1999
    Posts
    111

    Re: Using Realloc with the result of New?

    I can't quote a definate answer for you, but I would strongly caution against doing this even if your compiler will allow it. Write a realloc function that uses new to allocate a larger buffer, memcpy, and delete the original.

    Roger C. Scudder Jr.
    Annance Consulting
    Wayne, Pennsylvania, US

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Using Realloc with the result of New?

    The answer is "don't do it". realloc() and new() are different things that are not to be mixed together. The new() calls constructors, while realloc has no idea of objects or constructors.

    You can't mix a call to new() with free(), or malloc() with delete(). The same thing goes with new() with realloc()/calloc().

    Regards,

    Paul McKenzie


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