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. Is there a memory limit for the "new" operator?

Is there a memory limit for the "new" operator?

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelpquestion
6 Posts 4 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.
  • C Offline
    C Offline
    clintsinger
    wrote on last edited by
    #1

    I am writing a program that was working fine until I added one more variable. Instead of 2 char* I now have three. Each char* is allocated using the new operator and a size of 524,920. Everything works fine until I put in that third variable. Now I get a dynamic memory overrun error, even when I don't touch the data. Any Ideas? Thanks in advance, Clint

    X L 2 Replies Last reply
    0
    • C clintsinger

      I am writing a program that was working fine until I added one more variable. Instead of 2 char* I now have three. Each char* is allocated using the new operator and a size of 524,920. Everything works fine until I put in that third variable. Now I get a dynamic memory overrun error, even when I don't touch the data. Any Ideas? Thanks in advance, Clint

      X Offline
      X Offline
      Xian
      wrote on last edited by
      #2

      I've read there is a 64k dynamic allocation limit on arrays. ---- Xian

      1 Reply Last reply
      0
      • C clintsinger

        I am writing a program that was working fine until I added one more variable. Instead of 2 char* I now have three. Each char* is allocated using the new operator and a size of 524,920. Everything works fine until I put in that third variable. Now I get a dynamic memory overrun error, even when I don't touch the data. Any Ideas? Thanks in advance, Clint

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        I'm not sure if this coincide with what you need... I needed a buffer for file manipulation. The "new" seemed to be limited to 64k of memory. A work around this uses structures. Declare a structure with elements (in my case, BYTE) as array of size 0xff (65,535). If you need more than 64k of memory, declare more array of BYTE's. In order to use it, declare a variable of the structure and a pointer to BYTE. Then point the pointer to the first element of the structure, and voila!, you have a buffer array of more than 64k! Just use the pointer to access the buffer. (elements declared in a structure are allocated continously). Note: if elements are of size 0xff each, I noticed that one can not have more than 16 elements. Ofcourse, I might be wrong. typedef struct BUFFER { BYTE Buffer0 [0xff]; BYTE Buffer1 [0xff]; ... BYTE BufferN [0xff]; } BUFFER; void Some_Function () { BUFFER Buffer; BYTE *pBuffer; pBuffer = Buffer.Buffer0; memset (pBuffer, 0, ); ... } :)

        A 1 Reply Last reply
        0
        • L Lost User

          I'm not sure if this coincide with what you need... I needed a buffer for file manipulation. The "new" seemed to be limited to 64k of memory. A work around this uses structures. Declare a structure with elements (in my case, BYTE) as array of size 0xff (65,535). If you need more than 64k of memory, declare more array of BYTE's. In order to use it, declare a variable of the structure and a pointer to BYTE. Then point the pointer to the first element of the structure, and voila!, you have a buffer array of more than 64k! Just use the pointer to access the buffer. (elements declared in a structure are allocated continously). Note: if elements are of size 0xff each, I noticed that one can not have more than 16 elements. Ofcourse, I might be wrong. typedef struct BUFFER { BYTE Buffer0 [0xff]; BYTE Buffer1 [0xff]; ... BYTE BufferN [0xff]; } BUFFER; void Some_Function () { BUFFER Buffer; BYTE *pBuffer; pBuffer = Buffer.Buffer0; memset (pBuffer, 0, ); ... } :)

          A Offline
          A Offline
          Anders Molin
          wrote on last edited by
          #4

          Just vondering why you don't use malloc() instead. :confused: - Anders Money talks, but all mine ever says is "Goodbye!"

          C 1 Reply Last reply
          0
          • A Anders Molin

            Just vondering why you don't use malloc() instead. :confused: - Anders Money talks, but all mine ever says is "Goodbye!"

            C Offline
            C Offline
            clintsinger
            wrote on last edited by
            #5

            Well from the CRT source code it looks like malloc was using from the dynamic heap. I looked into the heap size and it can't be bigger than about 500k. I ended up just saving that precious heap and used GlobalAlloc instead.

            A 1 Reply Last reply
            0
            • C clintsinger

              Well from the CRT source code it looks like malloc was using from the dynamic heap. I looked into the heap size and it can't be bigger than about 500k. I ended up just saving that precious heap and used GlobalAlloc instead.

              A Offline
              A Offline
              Anders Molin
              wrote on last edited by
              #6

              It uses memory from the global heap. It's no problem to alloc 50MB with malloc() - Anders Money talks, but all mine ever says is "Goodbye!"

              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