I am writing an object into Parcel which has an icon field.
While putting breakpoint in the writeToParcel
method, I observed that the parcel size before writing the icon is 22456
bytes.
The Icon
is of type data and here's what toString
gives in the debugger:
Icon(typ=DATA len=31189)
which says that the data length is 31189 bytes
, verified this by calling getDataBytes
inside the class.
However, after this icon is written onto the parcel, the parcel size comes out to be 22572
bytes, which is just 116
bytes more than what it was.
So it seems that something is happening behind the scenes when writing the icon. I couldn't conclude it by looking the source code for Icon class.
Can someone please explain what's going on here? I've seen some references for ashmen memory in the class but I am not really sure what that means and how it'd add upto this.
Edit: For another object where the preview is Icon(typ=DATA len=11129)
, the parcel size increases by the same 11129
bytes.
Edit 2:
original size: Icon(typ=DATA len=4864) , bytes taken in parcel: 4888
original size: Icon(typ=DATA len=4314) , bytes taken in parcel: 4340
original size: Icon(typ=DATA len=4314) , bytes taken in parcel: 4340
original size: Icon(typ=DATA len=31189) , bytes taken in parcel: 48
original size: Icon(typ=DATA len=11129) , bytes taken in parcel: 11156
original size: Icon(typ=DATA len=58126) , bytes taken in parcel: 48
original size: Icon(typ=DATA len=11705) , bytes taken in parcel: 11732
original size: Icon(typ=DATA len=7713) , bytes taken in parcel: 7740
original size: Icon(typ=DATA len=7713) , bytes taken in parcel: 7740
Got an answer to this after digging into the native code.
As we can see here, the in-place blob limit for the parcel is 16KB. If it's larger than that, it is copied into a shared ashmem region.