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 problem in CSharedFile.

Memory problem in CSharedFile.

Scheduled Pinned Locked Moved C / C++ / MFC
comperformancehelpquestion
4 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.
  • A Offline
    A Offline
    Aditya_Palanki
    wrote on last edited by
    #1

    Hi, I found a peculiar problem when using CSharedFile. Requirement: I have data present in (BYTE*) which needs to be converted to HGLOBAL. The data is segmented, that is the entire data is present in 2-3 BYTE*. What was done: a) Created a CSharedFile and attached it to a CArchive object. Then the entire BYTE* data was archived using a while loop for each BYTE*. b) Called CSharedFile::Detach to obtain the HGLOBAL data. Problem: The actual size of the data is 1184 bytes. But when checking the actual size of the memory allocated using GlobalSize() function the return value was 8192!!! Please let me know what could be the reason for this? You can reach me at s_adityapalanki@yahoo.com Thanks and regards, Aditya Palanki

    J 1 Reply Last reply
    0
    • A Aditya_Palanki

      Hi, I found a peculiar problem when using CSharedFile. Requirement: I have data present in (BYTE*) which needs to be converted to HGLOBAL. The data is segmented, that is the entire data is present in 2-3 BYTE*. What was done: a) Created a CSharedFile and attached it to a CArchive object. Then the entire BYTE* data was archived using a while loop for each BYTE*. b) Called CSharedFile::Detach to obtain the HGLOBAL data. Problem: The actual size of the data is 1184 bytes. But when checking the actual size of the memory allocated using GlobalSize() function the return value was 8192!!! Please let me know what could be the reason for this? You can reach me at s_adityapalanki@yahoo.com Thanks and regards, Aditya Palanki

      J Offline
      J Offline
      Johan Rosengren
      wrote on last edited by
      #2

      This is the documented behaviour for GlobalSize.

      A 1 Reply Last reply
      0
      • J Johan Rosengren

        This is the documented behaviour for GlobalSize.

        A Offline
        A Offline
        Aditya_Palanki
        wrote on last edited by
        #3

        Dear Johan, Does this mean that the extra memory that is being allocated is normal? Can you suggest any other way of creating an HGLOBAL? Regards, Aditya Palanki

        J 1 Reply Last reply
        0
        • A Aditya_Palanki

          Dear Johan, Does this mean that the extra memory that is being allocated is normal? Can you suggest any other way of creating an HGLOBAL? Regards, Aditya Palanki

          J Offline
          J Offline
          Johan Rosengren
          wrote on last edited by
          #4

          Aditya_Palanki wrote: Does this mean that the extra memory that is being allocated is normal? Yes, it allocates in blocks. If your allocation size is not an exact multiple of the block, you'll get extra padding. Aditya_Palanki wrote: Can you suggest any other way of creating an HGLOBAL? GlobalAlloc is the way of doing it. If the receiver needs to know the size actually allocated, just add this value to the beginning of the block, for example.

          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