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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Oddity Copying Global Memory

Oddity Copying Global Memory

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresbusinessperformancehelp
2 Posts 2 Posters 1 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
    Steve Thresher
    wrote on last edited by
    #1

    Can anybody tell me why copying an unlocked block of global memory using memcpy() would cause the call stack to change. The code looked like this: UINT size=GlobalSize(hGlobal); LPBYTE pBuffer=new BYTE[size]; // Buffer allocation is successful memcpy(pBuffer,hGlobal,size); // <-- Call stack changes in memcpy() I realised the problem was caused by not using GlobalLock() to get the actual address of the memory to copy but I have no idea why using the hGlobal handle as the source address would cause the call stack to change! Systems AXIS Ltd - Software for Business ...

    M 1 Reply Last reply
    0
    • S Steve Thresher

      Can anybody tell me why copying an unlocked block of global memory using memcpy() would cause the call stack to change. The code looked like this: UINT size=GlobalSize(hGlobal); LPBYTE pBuffer=new BYTE[size]; // Buffer allocation is successful memcpy(pBuffer,hGlobal,size); // <-- Call stack changes in memcpy() I realised the problem was caused by not using GlobalLock() to get the actual address of the memory to copy but I have no idea why using the hGlobal handle as the source address would cause the call stack to change! Systems AXIS Ltd - Software for Business ...

      M Offline
      M Offline
      Mukkie
      wrote on last edited by
      #2

      Hello! GlobalAlloc() returns a "handle to the newly allocated memory object", and this does not mean pointer to allocated memory. So I suspect, that this handle is a pointer to structure, in which one of the field is pointer to memory (only suspission). But: it did not overwrite my stack: HANDLE hGlobal = GlobalAlloc( GMEM_ZEROINIT, 2048); UINT size=GlobalSize(hGlobal); LPBYTE pBuffer=new BYTE[size]; // Buffer allocation is successful memcpy(pBuffer,hGlobal,size); // <-- Call stack changes in memcpy() If you want to use memory pointer, take a look at the flag GMEM_FIXED in GlobalAlloc() :)

      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