Size of an object in memory at runtime

Are you using the Windows clipboard mechanism (OpenClipboard, SetClipboardData...)? What does the object look like that you are putting on the clipboard? Is it always the same concrete type or do you have an abstract base class and you are putting different derived types on the clipboard? Is it a simple class with only value members or does it have arrays or pointers to other objects? Josh On 28/11/11 12:37 PM, skunkworks-request@lists.my.co.ke wrote:
Message: 3 Date: Mon, 28 Nov 2011 12:35:08 +0300 From: James Nzomo<kazikubwa@gmail.com> To: Skunkworks Mailing List<skunkworks@lists.my.co.ke> Subject: Re: [Skunkworks] Size of an object in memory at runtime Message-ID: <CAChuKuewWX4DQzr3foEo7KU550vAwzRrevtgVDMw2Tp6Qwz2GQ@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1"
What i'm trying to do is implement drag& drop clipboard opps for a custom data object (a custom class/object in this case) that works accross multiple instances of the same running application.
In order to do this efficiently, i have to allocate the exact amount of memory required to store the class instance as a D&D object.
The other alternatives would be to give a generous over estimate of the required memory or to use the objects JSON string as the D&D object. But the latter requires alot of coding overhead.

I'm using wxWidgets. It's clipboard mechanism extends the underlying platform's clipboard mechanism. The object is of a custom class. This class contains various datatypes ranging from ints,doubles,std::strings,char pointers to custom typedefs, structs and other classes. The objects i want to D&D are of different types. I will have a clipboard data object for each type as opposed to having an abstract implementation which is more complex. _______________________________________________ *Good judgement comes from Experience.* *Most of that comes from Bad Judgement.* _______________________________________________ * * 2011/11/28 Josh Handley <josh@bridgeinternationalacademies.com>
Are you using the Windows clipboard mechanism (OpenClipboard, SetClipboardData...)?
What does the object look like that you are putting on the clipboard? Is it always the same concrete type or do you have an abstract base class and you are putting different derived types on the clipboard? Is it a simple class with only value members or does it have arrays or pointers to other objects?
Josh
On 28/11/11 12:37 PM, skunkworks-request@lists.my.**co.ke<skunkworks-request@lists.my.co.ke>wrote:
Message: 3 Date: Mon, 28 Nov 2011 12:35:08 +0300 From: James Nzomo<kazikubwa@gmail.com> To: Skunkworks Mailing List<skunkworks@lists.my.co.ke**> Subject: Re: [Skunkworks] Size of an object in memory at runtime Message-ID: <CAChuKuewWX4DQzr3foEo7KU550vA**wzRrevtgVDMw2Tp6Qwz2GQ@mail.** gmail.com<CAChuKuewWX4DQzr3foEo7KU550vAwzRrevtgVDMw2Tp6Qwz2GQ@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
What i'm trying to do is implement drag& drop clipboard opps for a custom data object (a custom class/object in this case) that works accross multiple instances of the same running application.
In order to do this efficiently, i have to allocate the exact amount of memory required to store the class instance as a D&D object.
The other alternatives would be to give a generous over estimate of the required memory or to use the objects JSON string as the D&D object. But the latter requires alot of coding overhead.
______________________________**_________________ Skunkworks mailing list Skunkworks@lists.my.co.ke ------------ List info, subscribe/unsubscribe http://lists.my.co.ke/cgi-bin/**mailman/listinfo/skunkworks<http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks> ------------
Skunkworks Rules http://my.co.ke/phpbb/**viewtopic.php?f=24&t=94<http://my.co.ke/phpbb/viewtopic.php?f=24&t=94> ------------ Other services @ http://my.co.ke

The only barrier to an efficient/elegant solution is accurately determining the size of the object, so that the exact amount of memory can be "malloc"ed for it. If any less is provided, the OS will SIGSEGV the living daylights out of my app if it tries to access any object member addressed outside the app's memory. _______________________________________________ *Good judgement comes from Experience.* *Most of that comes from Bad Judgement.* _______________________________________________ * * 2011/11/28 James Nzomo <kazikubwa@gmail.com>
I'm using wxWidgets. It's clipboard mechanism extends the underlying platform's clipboard mechanism.
The object is of a custom class. This class contains various datatypes ranging from ints,doubles,std::strings,char pointers to custom typedefs, structs and other classes.
The objects i want to D&D are of different types. I will have a clipboard data object for each type as opposed to having an abstract implementation which is more complex.
_______________________________________________
*Good judgement comes from Experience.* *Most of that comes from Bad Judgement.* _______________________________________________ *
*
2011/11/28 Josh Handley <josh@bridgeinternationalacademies.com>
Are you using the Windows clipboard mechanism (OpenClipboard, SetClipboardData...)?
What does the object look like that you are putting on the clipboard? Is it always the same concrete type or do you have an abstract base class and you are putting different derived types on the clipboard? Is it a simple class with only value members or does it have arrays or pointers to other objects?
Josh
On 28/11/11 12:37 PM, skunkworks-request@lists.my.**co.ke<skunkworks-request@lists.my.co.ke>wrote:
Message: 3 Date: Mon, 28 Nov 2011 12:35:08 +0300 From: James Nzomo<kazikubwa@gmail.com> To: Skunkworks Mailing List<skunkworks@lists.my.co.ke**> Subject: Re: [Skunkworks] Size of an object in memory at runtime Message-ID: <CAChuKuewWX4DQzr3foEo7KU550vA**wzRrevtgVDMw2Tp6Qwz2GQ@mail.** gmail.com<CAChuKuewWX4DQzr3foEo7KU550vAwzRrevtgVDMw2Tp6Qwz2GQ@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
What i'm trying to do is implement drag& drop clipboard opps for a custom data object (a custom class/object in this case) that works accross multiple instances of the same running application.
In order to do this efficiently, i have to allocate the exact amount of memory required to store the class instance as a D&D object.
The other alternatives would be to give a generous over estimate of the required memory or to use the objects JSON string as the D&D object. But the latter requires alot of coding overhead.
______________________________**_________________ Skunkworks mailing list Skunkworks@lists.my.co.ke ------------ List info, subscribe/unsubscribe http://lists.my.co.ke/cgi-bin/**mailman/listinfo/skunkworks<http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks> ------------
Skunkworks Rules http://my.co.ke/phpbb/**viewtopic.php?f=24&t=94<http://my.co.ke/phpbb/viewtopic.php?f=24&t=94> ------------ Other services @ http://my.co.ke

Have you considered implementing your class as a template class that way you can handle all the specific data types you want to D&D at runtime and get a more accurate value to allocate to memory using the sizeof() operator. You might not know the type of the data being D&D so you might want to add the following header #include <typeinfo.h> to get the actually type of the data then call typeid(theObject).name(); I have not actually used this but i vague remember it being handy in such a case. corrections welcome. Or you could if else through all supported types and check for a not null with a dynamic cast then apply the sizeof on the successful cast ----- Original Message ----- | From: "James Nzomo" <kazikubwa@gmail.com> | To: "Skunkworks Mailing List" <skunkworks@lists.my.co.ke> | Sent: Monday, November 28, 2011 1:01:49 PM | Subject: Re: [Skunkworks] Size of an object in memory at runtime | I'm using wxWidgets. It's clipboard mechanism extends the underlying | platform's clipboard mechanism. | The object is of a custom class. | This class contains various datatypes ranging from | ints,doubles,std::strings,char pointers to custom typedefs, structs | and other classes. | The objects i want to D&D are of different types. I will have a | clipboard data object for each type as opposed to having an abstract | implementation which is more complex. | _______________________________________________ | Good judgement comes from Experience. | Most of that comes from Bad Judgement. | _______________________________________________ | 2011/11/28 Josh Handley < josh@bridgeinternationalacademies.com > | _______________________________________________ | Skunkworks mailing list | Skunkworks@lists.my.co.ke

I don't think the template class route allows for a reliable way to get the exact object size. Remember the size i am talking about is also determined by state i.e. the contents of variable size members. _______________________________________________ *Good judgement comes from Experience.* *Most of that comes from Bad Judgement.* _______________________________________________ * * 2011/11/28 Steve Obbayi <steve@sobbayi.com>
Have you considered implementing your class as a template class that way you can handle all the specific data types you want to D&D at runtime and get a more accurate value to allocate to memory using the sizeof() operator.
You might not know the type of the data being D&D so you might want to add the following header
#include <typeinfo.h>
to get the actually type of the data then call
typeid(theObject).name();
I have not actually used this but i vague remember it being handy in such a case. corrections welcome.
Or you could if else through all supported types and check for a not null with a dynamic cast then apply the sizeof on the successful cast
------------------------------
*From: *"James Nzomo" <kazikubwa@gmail.com> *To: *"Skunkworks Mailing List" <skunkworks@lists.my.co.ke> *Sent: *Monday, November 28, 2011 1:01:49 PM
*Subject: *Re: [Skunkworks] Size of an object in memory at runtime
I'm using wxWidgets. It's clipboard mechanism extends the underlying platform's clipboard mechanism.
The object is of a custom class. This class contains various datatypes ranging from ints,doubles,std::strings,char pointers to custom typedefs, structs and other classes.
The objects i want to D&D are of different types. I will have a clipboard data object for each type as opposed to having an abstract implementation which is more complex.
_______________________________________________
*Good judgement comes from Experience.* *Most of that comes from Bad Judgement.* _______________________________________________ *
*
2011/11/28 Josh Handley <josh@bridgeinternationalacademies.com>
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke ------------ List info, subscribe/unsubscribe http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------
Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
participants (3)
-
James Nzomo
-
Josh Handley
-
Steve Obbayi