|
Boost Users : |
Subject: Re: [Boost-users] [Serialization] Serialization of function pointers
From: Jeremy Pack (rostovpack_at_[hidden])
Date: 2009-11-12 14:36:46
On Thu, Nov 12, 2009 at 2:55 AM, elizabeta petreska <
elizabeta.petreska_at_[hidden]> wrote:
> Hello everybody
> This is my first post to the list.
> Can I serialize C++ function pointer ? I search around and found that it
> could not be done ( although I am not sure ).
> If it can not be done, whats the explanation about it ?
> Thanks
>
The location of a function pointer in the address space could change
depending on a number of factors:
- The binary being recompiled
- Any function pointers to functions in shared libraries could be
invalidated
- On some obscure platforms, this could still fail, even with the same
binary that doesn't load any shared libraries
So, it could possibly work, but I would highly recommend that you don't do
this.
Other options:
- Wrap your functions in classes, and use the standard serialization methods
for class objects.
- Have a function in your binary that registers all of the function pointers
(a std::map would suffice) that you care about at startup, perhaps indexed
by a string. Then, serialize the names of the functions that you want to
save.
Can you describe your use case in more detail?
Jeremy
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net