Jump to content

  • Log In with Google      Sign In   
  • Create Account


How do i use sizeof when creating a library?(visual studio)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 noatom   Members   -  Reputation: 769

Like
0Likes
Like

Posted 10 September 2013 - 05:23 PM

So I recently ran into this problem.How does one get the size of a certain type of object when creating a library?



Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 7782

Like
4Likes
Like

Posted 10 September 2013 - 05:38 PM

Can you explain your problem more than just referring to it as "this" problem? Using the sizeof operator on a type is no different in a library than anywhere else.



#3 AllEightUp   Moderators   -  Reputation: 4120

Like
4Likes
Like

Posted 10 September 2013 - 08:46 PM

I "suspect" the intention is to do something like a plugin system. I.e. you have a class in a library derived from an interface which can be used via a factory. If you want to store such an object in a pool though, you need to know the size of the object in memory which you can't do since you don't know diddly about the runtime linked classes. If this is *not* correct, ignore the following:

Basically, you can't do it. That is not to say you can not get the same effect though. You have to sidestep the issue and basically implement a static function which can be called to get the sizeof. Assuming you use a centralized factory, when you register the type, pass in the 'sizeof' at that time. Instead of doing "sizeof( something )", you now use "factory->SizeOf( something )". How you refer to 'something' is up to you, Id/GUID etc. There are many ways to work around this in a dynamic link environment, if you don't have a centralized factory, you can always use a per dll function which includes all the sizes so you can ask the actual Dll in that case.

Mostly though, Brother Bob has the correct question. I'm just making a best guess assumption based on the reasons I've needed such information in the past.

#4 noatom   Members   -  Reputation: 769

Like
0Likes
Like

Posted 11 September 2013 - 01:35 AM

AllEigthUp,that was what i was asking,thanks.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS