[ANet-devel] Starting the code!
Status: Abandoned
Brought to you by:
benad
From: Benoit N. <be...@ma...> - 2000-12-26 15:40:17
|
As recommended by Ajaya, I'll start a bit on the code. Actually, just some basic cross-platform header files and some function declarations. Most importantly, I'll start the specific design of the "ANet Client SDK". Basically, it's just a library that will do the actual process-to-process communication so that you don't have to care about how that works on a specific OS, making cross-platform client coding (especially Java ones) much more easier. And I'm already having a problem! An example: Pascal Strings. The format is simple: unsigned char length; char string[length]; No "NULL" character is needed at the end of the string, though Pascal strings cannot be longer than 255 bytes. Now, try to make a C structure out of this. One MAJOR limitation of structures is that the size of the structure, in bytes, MUST be known at compile-time. And with ANet, I'm trying to do things like this: unsigned char nbrServices; ServiceNbr services[nbrServices]; Obviously, you can do "malloc", then play inside that allocated memory (whose size is known at run-time) using some clever typecasting: //i is the number of services, at known at run-time //servicesArray are the service numbers, at run-time char *myStruct = (char*)malloc(sizeof(unsigned char)+i*sizeof(ServiceNbr)); char *curPos = myStruct; int j; *((unsigned char*)curPos) = i; curPos += sizeof(unsigned char); for (j = 0; j < i; j++) { *((ServiceNbr*)curPos) = servicesArray[j]; curPos += sizeof(ServiceNbr); } While, in theory, this code is 100% cross-platform and totally unaffected by any memory alignment optimizations, it's a real pain in the a** to code... The danger here is that "clever" programmers may think they just have found an easier way to do this, while they are actually breaking up everything. For example, doing this might screw up your data (memory alignment, again): ((ServiceNbr*)curPos)[j] = servicesArray[j]; So, any easier way to do this? - Benad |