Getting byte size of POD classes and dynamic arrays

1100110 0b1100110 at gmail.com
Thu May 16 06:35:13 PDT 2013


On 05/16/2013 08:21 AM, Byron Heads wrote:
> On Thu, 16 May 2013 08:11:35 -0500, 1100110 wrote:
> 
>> On 05/16/2013 08:09 AM, Byron Heads wrote:
>>> I am working on d-leveldb wrapper (https://github.com/bheads/d-leveldb)
>>> and I need to be able to pass blocks of data between D and leveldb API.
>>> I am having rouble getting the byte size of dynamic arrays and POD
>>> classes.
>>>
>>> I can get the right size for 1D dynamic arrays, need a way to compute
>>> the total size.
>>>
>>> POD Classes always give me the size of the ref, is it possible?
>>>
>>> -Byron
>>
>>
>> __traits(classInstanceSize, MyClass); ?
> 
> I missed that one, in my test it returns 29 bytes,
> 8 for __vptr
> 8 for __monitor
> 13 for data
> 
> now I am wondering way a POD has a vtable.  Either way its not safe to 
> store a byte copy in to leveldb

Why not just use a struct?  .sizeof gives those accurately.  Oh you
wanted both...

Maybe take a look at vibe's rest interface?  It extracts the members of
classes and does funny things with them.  Can't say I understand it.
Over my head...

https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/http/rest.d

or
final class MyPodClass {} ?

And yeah, if you get stuck, std.traits is a really rich resource. =D


Good luck!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 900 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130516/b68d9df3/attachment.pgp>


More information about the Digitalmars-d-learn mailing list