Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Reallocation

Reallocation

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hint_54
    wrote on last edited by
    #1

    Is it possible to reallocate using operator new? // C some_ptr = malloc( sizeof( some_type ) * n ); ... // change "n" some_ptr = realloc( sizeof( some_type ) * n ); // C++ some_ptr = new some_type[n]; ... // change "n" // Now what? Best regards hint_54

    W M 2 Replies Last reply
    0
    • H hint_54

      Is it possible to reallocate using operator new? // C some_ptr = malloc( sizeof( some_type ) * n ); ... // change "n" some_ptr = realloc( sizeof( some_type ) * n ); // C++ some_ptr = new some_type[n]; ... // change "n" // Now what? Best regards hint_54

      W Offline
      W Offline
      Waldermort
      wrote on last edited by
      #2

      The short answer is no. Either use a combination of malloc and realloc as in your example, or use the keyword new and copy the contents over to a larger buffer.

      H 1 Reply Last reply
      0
      • W Waldermort

        The short answer is no. Either use a combination of malloc and realloc as in your example, or use the keyword new and copy the contents over to a larger buffer.

        H Offline
        H Offline
        hint_54
        wrote on last edited by
        #3

        Ok, thanks hint_54

        1 Reply Last reply
        0
        • H hint_54

          Is it possible to reallocate using operator new? // C some_ptr = malloc( sizeof( some_type ) * n ); ... // change "n" some_ptr = realloc( sizeof( some_type ) * n ); // C++ some_ptr = new some_type[n]; ... // change "n" // Now what? Best regards hint_54

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          Use an STL collection such as vector, and you won't have to worry about the memory allocation.

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups