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. diff b/w heapalloc and new

diff b/w heapalloc and new

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
10 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.
  • S Offline
    S Offline
    sunit5
    wrote on last edited by
    #1

    what is the diff b/w heapalloc and new . Pls help me. never say die

    S T 2 Replies Last reply
    0
    • S sunit5

      what is the diff b/w heapalloc and new . Pls help me. never say die

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      new uses HeapAlloc internally. But it also adds caching and small block heaps and the like on top of it. new is a C++ keyword where as HeapAlloc is a Win32 API function. Steve

      S 1 Reply Last reply
      0
      • S sunit5

        what is the diff b/w heapalloc and new . Pls help me. never say die

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        i don't find HeapAlloc()[^] that similar to new operator... why not using the language operator, so that it will always work regardless of the plateform ?!

        1 Reply Last reply
        0
        • S Stephen Hewitt

          new uses HeapAlloc internally. But it also adds caching and small block heaps and the like on top of it. new is a C++ keyword where as HeapAlloc is a Win32 API function. Steve

          S Offline
          S Offline
          sunit5
          wrote on last edited by
          #4

          Thanks for the answer. But i want to know is there any thing like private heap and Global heap? Pls help me never say die

          S 1 Reply Last reply
          0
          • S sunit5

            Thanks for the answer. But i want to know is there any thing like private heap and Global heap? Pls help me never say die

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #5

            No. Win32 supports multiple heaps, you can create your own by calling HeapCreate and keep it to yourself - I guess in that case you could consider it private. Can you explain what you’re trying to do specifically? Maybe then I can be of more help. Steve

            S 1 Reply Last reply
            0
            • S Stephen Hewitt

              No. Win32 supports multiple heaps, you can create your own by calling HeapCreate and keep it to yourself - I guess in that case you could consider it private. Can you explain what you’re trying to do specifically? Maybe then I can be of more help. Steve

              S Offline
              S Offline
              sunit5
              wrote on last edited by
              #6

              Actually a project has been given to me which connects the client to IIS Server via soap.I have been assigned to devlope further.So any memory allocation done on Server Side using Heapalloc. When I asked the reason ,i was told that memory is bound(within) to the process so it has been done using HeapAlloc. If u can help me further,I would be thankful to u never say die

              S 1 Reply Last reply
              0
              • S sunit5

                Actually a project has been given to me which connects the client to IIS Server via soap.I have been assigned to devlope further.So any memory allocation done on Server Side using Heapalloc. When I asked the reason ,i was told that memory is bound(within) to the process so it has been done using HeapAlloc. If u can help me further,I would be thankful to u never say die

                S Offline
                S Offline
                Stephen Hewitt
                wrote on last edited by
                #7

                Calling new in C++ gets its memory from HeapAlloc underneath the hood. But it integrates with the language by: - Knowing the size of the object it’s allocating (so you don't have to supply it). - Calls constructors (and delete calls destructors). - Avoids casts. In short I'd just use new and delete. But beware:  If you allocate with new you must free with delete and if you allocate with HeapAlloc you must free it with HeapFree - You can't allocate some memory with new and free the same memory with HeapFree for example. Steve

                S 1 Reply Last reply
                0
                • S Stephen Hewitt

                  Calling new in C++ gets its memory from HeapAlloc underneath the hood. But it integrates with the language by: - Knowing the size of the object it’s allocating (so you don't have to supply it). - Calls constructors (and delete calls destructors). - Avoids casts. In short I'd just use new and delete. But beware:  If you allocate with new you must free with delete and if you allocate with HeapAlloc you must free it with HeapFree - You can't allocate some memory with new and free the same memory with HeapFree for example. Steve

                  S Offline
                  S Offline
                  sunit5
                  wrote on last edited by
                  #8

                  That means if a memory allocation requires construtor for intialization then use new rather than HeapAlloc never say die

                  S 1 Reply Last reply
                  0
                  • S sunit5

                    That means if a memory allocation requires construtor for intialization then use new rather than HeapAlloc never say die

                    S Offline
                    S Offline
                    Stephen Hewitt
                    wrote on last edited by
                    #9

                    You could use the a placment new but that's rather advanced. Steve

                    S 1 Reply Last reply
                    0
                    • S Stephen Hewitt

                      You could use the a placment new but that's rather advanced. Steve

                      S Offline
                      S Offline
                      sunit5
                      wrote on last edited by
                      #10

                      Thanx a lot never say die

                      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