How to dereference multiple void pointers in structs into 1 piece of memory?

LCM supports variable length arrays, see the "Arrays" section in the reference manual: lcm.googlecode.com/svn-history/r401/www/... However, your data is accessed via void which is just a pointer to an "unknown" type. If your data is just bytes, then it might work to treat it as a byte array, like this in your LCM definition: struct pack2 { int32_t data_size; unsigned char datadata_size}; }.

LCM supports variable length arrays, see the "Arrays" section in the reference manual: lcm.googlecode.com/svn-history/r401/www/... However, your data is accessed via void*, which is just a pointer to an "unknown" type. If your data is just bytes, then it might work to treat it as a byte array, like this in your LCM definition: struct pack2 { int32_t data_size; unsigned char datadata_size}; }.

Any time you serialize a data structure containing pointers, you need to convert those pointers into something other than pointers. One possibility is to turn them into offsets within the data stream; another possibility is to remove them altogether and rely on the organization of the stream itself. Either way, you need to write down the serialization format with great precision; the rule of thumb is, someone should be able to write code from scratch that either produces or consumes the serialization without any information other than the specification you write.

Here's one possible way to serialize the data structures you showed: # Each row is a 32-bit unsigned value in network byte order. | number of pairs following | | 0. Value1 | | 0.

Value2 | | 1. Value1 | | 2. Value2 | ... | N.

Value1 | | N. Value2 | Good examples - both of how to do this sort of thing and how to document it - may be found in the TCP and IP RFCs, or the PNG specification.

1 Note: he's using LCM, which should handle all the marshalling. See: code.google. Com/p/lcm – payne Feb 7 at 20:15 Didn't recognize the acronym; thanks for the pointer.

– Zack Feb 7 at 20:20.

Please keep in mind that a struct may contain any number of padding bytes. This is especially troublesome when writing any form of data protocol. If using sizeof() on it, you must be sure that the compiler has padding disabled.

The portable way is to go through the struct member by member and send them.

You can do it like this: struct pack2 *p; p = (struct pack2 *) malloc( sizeof(struct pack2) + 1024 ); p->data_size = 1024; p->data = (char *) p + sizeof(struct pack2); The only caveat is that you have to make sure the target platform maintains the endianness of the original platform in data_size and you have to be sure struct pack2 is the same size on both platforms.

All the processes should run on the same machine, using the same source code... – Sergio Campamá Feb 8 at 13:29 Just an example. You're going to record the actual size of the data in the data_size member.It can be as big as you need. I was demonstrating how to make a linear block of memory that contains the struct itself and the struct data.

– par Feb 8 at 20:23 shouldn't it be + 1024 instead of * 1024? – Sergio Campamá Feb 8 at 21:01 Yes. Nice catch on the typo and fixed now.

– par Feb 8 at 5:52.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions