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

Started by
2 comments, last by noatom 10 years, 7 months ago

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

Advertisement

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.

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.

AllEigthUp,that was what i was asking,thanks.

This topic is closed to new replies.

Advertisement