0

I have a file named Point.c which has a structure defined named as:

Point

Also, it has functions in it named point_str, point_deserialize.

Now, there are similar files like these like

LinkedList.c, Node.c etc with similar definitions.

Now, I am calling these functions dynamically in another file by using dlopen.

So, if I find that the type is Point, I will create a string:

point_str

and call the function by giving the path to the .so file using dlopen.

But, I am not able to know the size of the structure dynamically. Is there a way to do it? I want to do something like

int size = givemesize("Point", "path_to_so");

Which is just like dlopen but to know the size of a structure.

Edit: why I want to know the size?

With that size I am deserializing anything from string to its actual type. That's why I need the size. So, from command line it comes to deserialize a Point object. So, with that string I want to know the actual size of the Point object which resides in Point.c and has a libpoint.so

4

1 回答 1

1

你不能。

.so 不知道结构的大小,除非您将其编码为 .so 可用的函数(如 Jonathan 在评论中所说)。所有这些信息都在编译时被丢弃。在编译期间计算任何相关的指针/内存偏移量,并丢弃用于计算这些偏移量的信息。

于 2013-07-26T17:32:56.543 回答