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. Memory from heap

Memory from heap

Scheduled Pinned Locked Moved C / C++ / MFC
performance
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.
  • J Offline
    J Offline
    John theKing
    wrote on last edited by
    #1

    Hi!! A program allocated memory from heap using new, something like this int * a = new int[20]; i.e program created ten int objects using heap. Later in the program suppose we only require first ten of these while other are found useless, then how can we delete the objects from int[10] to int[19]

    C 1 Reply Last reply
    0
    • J John theKing

      Hi!! A program allocated memory from heap using new, something like this int * a = new int[20]; i.e program created ten int objects using heap. Later in the program suppose we only require first ten of these while other are found useless, then how can we delete the objects from int[10] to int[19]

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I dunno if you can delete the last 10 only, but the safest bet is to make a new int[10] and copy the 10 you want into it. Easier, just use std::vector instead. Christian NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma Anonymous wrote: OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window. I think you are a good candidate for Visual Basic. - Nemanja Trifunovic

      H 1 Reply Last reply
      0
      • C Christian Graus

        I dunno if you can delete the last 10 only, but the safest bet is to make a new int[10] and copy the 10 you want into it. Easier, just use std::vector instead. Christian NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma Anonymous wrote: OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window. I think you are a good candidate for Visual Basic. - Nemanja Trifunovic

        H Offline
        H Offline
        Hesham Amin
        wrote on last edited by
        #3

        Hi.. I think it's not possible using new , delete use malloc , realloc , free stuff to make it (include stdlib.h and malloc.h)or use STL or make a linked list instead of using arrays

        C 1 Reply Last reply
        0
        • H Hesham Amin

          Hi.. I think it's not possible using new , delete use malloc , realloc , free stuff to make it (include stdlib.h and malloc.h)or use STL or make a linked list instead of using arrays

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          A linked list will have completely different behaviour to a vector/self rolled array wrapper. You need to be careful that this is the sort of behaviour you want ( fast insert, slow lookup ) Christian NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma Anonymous wrote: OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window. I think you are a good candidate for Visual Basic. - Nemanja Trifunovic

          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