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. Size of memory pointed to by void * pointer.

Size of memory pointed to by void * pointer.

Scheduled Pinned Locked Moved C / C++ / MFC
performancetutorialquestion
6 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.
  • V Offline
    V Offline
    VC Maniac
    wrote on last edited by
    #1

    How to get the size of memory pointed by void * pointer? Thanks in advance!

    N J 2 Replies Last reply
    0
    • V VC Maniac

      How to get the size of memory pointed by void * pointer? Thanks in advance!

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      Generally there is no way that will work on all conditions. How ever if you are sure that, the pointer will be pointing to a memory allocated using new operator, you can use the _msize function.

      nave [OpenedFileFinder] [My Blog]

      1 Reply Last reply
      0
      • V VC Maniac

        How to get the size of memory pointed by void * pointer? Thanks in advance!

        J Offline
        J Offline
        Jijo Raj
        wrote on last edited by
        #3

        You could use _msize()[^]. For instance,

        #include "malloc.h"

        ...

        // Allocate 100 bytes.
        void* pPointer = new BYTE[100];

        // Get the size from void ptr. Remember, It will return size in bytes.
        int size = _msize( Ptr );

        Please note that it won't work if the memory is allocated in stack. Only for memory allocated on heap. Hope it helps. Regards, Jijo.

        _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

        V 1 Reply Last reply
        0
        • J Jijo Raj

          You could use _msize()[^]. For instance,

          #include "malloc.h"

          ...

          // Allocate 100 bytes.
          void* pPointer = new BYTE[100];

          // Get the size from void ptr. Remember, It will return size in bytes.
          int size = _msize( Ptr );

          Please note that it won't work if the memory is allocated in stack. Only for memory allocated on heap. Hope it helps. Regards, Jijo.

          _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

          V Offline
          V Offline
          VC Maniac
          wrote on last edited by
          #4

          Thank You. Now how do I write any structure to a xml node? Any idea? Thanks in advance!

          J 1 Reply Last reply
          0
          • V VC Maniac

            Thank You. Now how do I write any structure to a xml node? Any idea? Thanks in advance!

            J Offline
            J Offline
            Jijo Raj
            wrote on last edited by
            #5

            Ah! Now i got the context about what you're trying to do. Export the BITMAP to XML? Bravo! i'd say. ;) IMHO, Instead of dumping the BITMAP structure to XML, just get the bitmap data by calling GetBitmapBits()[^] and other necessary information such as width, height, color depth and save that to XML file. Later on by loading these values, you can recreate the bitmap by calling the function - CreateBitmap()[^]. Hope this helps you. Regards, Jijo.

            _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

            V 1 Reply Last reply
            0
            • J Jijo Raj

              Ah! Now i got the context about what you're trying to do. Export the BITMAP to XML? Bravo! i'd say. ;) IMHO, Instead of dumping the BITMAP structure to XML, just get the bitmap data by calling GetBitmapBits()[^] and other necessary information such as width, height, color depth and save that to XML file. Later on by loading these values, you can recreate the bitmap by calling the function - CreateBitmap()[^]. Hope this helps you. Regards, Jijo.

              _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

              V Offline
              V Offline
              VC Maniac
              wrote on last edited by
              #6

              yo buddy.. that will surely help. :-D Thanks!

              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