From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: allocated memory size Date: 23 May 2000 11:30:53 GMT Organization: Aachen University of Technology (RWTH) Lines: 41 Distribution: world Message-ID: <8gdq5d$j9h$1@nets3.rz.RWTH-Aachen.DE> References: <8gbas1$c2b$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE> NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 959081453 19761 137.226.32.75 (23 May 2000 11:30:53 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 23 May 2000 11:30:53 GMT Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Damian Yerrick wrote: > // NOT ANSI C!!! > // This is GNU C and perhaps C99. It uses zero-size arrays. > typedef struct vector_int > { > int _sizeInMem; // the current size of the array in core > int _numElems; // up to which place the array is currently filled > int v[0]; // the data > } vector_int; There's not really any need to leave the realm of ANSI C for dynamically sized arrays. You can make 'v' a pointer to the array element type. Or, to show you how I actually did it, in gnuplot: typedef struct dynarray { long size; /* alloced size of the array */ long end; /* index of first unused entry */ long increment; /* amount to increment size by, on realloc */ size_t entry_size; /* size of the entries in this array */ void *v; /* the vector itself */ } dynarray; You have to cast that void * to something else, before you use it. That can conveniently be done by a macro, i.e.: dynarray polygons; #define plist ((polygon *) polygons.v) init_dynarray(&polygons, sizeof(polygon), 100, 100); /* access to elements of the list: */ init_polygon(plist + i); /* or equivalently &(plist[i]) */ plist[i].normal.x = 0.5; -- Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.