Realloc with new and delete

This is a discussion on Realloc with new and delete within the C++ Programming forums, part of the General Programming Boards category; Ok after doing a search it appears there is no direct c++ equivlent to realloc. What I want to know ...

  1. #1
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681

    Realloc with new and delete

    Ok after doing a search it appears there is no direct c++ equivlent to realloc. What I want to know is if it is safe to use realloc with new and delete. The type will be char (I'm just getting a chuck of memory) and constructors/destructors do not need to be invoked.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,671
    >> What I want to know is if it is safe to use realloc with new and delete.
    The generic awnser is no.
    You can simulate realloc() using new and delete and memcpy(). If you need the efficiency of realloc() then use malloc() and free() for your char array.

    gg

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Kinda thought so.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21