Mercurial > hg > xemacs-beta
diff src/dynarr.c @ 185:3d6bfa290dbd r20-3b19
Import from CVS: tag r20-3b19
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:55:28 +0200 |
parents | 376386a54a3c |
children | c5d627a313b1 |
line wrap: on
line diff
--- a/src/dynarr.c Mon Aug 13 09:54:24 2007 +0200 +++ b/src/dynarr.c Mon Aug 13 09:55:28 2007 +0200 @@ -44,17 +44,19 @@ This is a container object. Declare a dynamic array of a specific type as follows: -struct mytype_dynarr +typdef struct { Dynarr_declare (mytype); -}; +} mytype_dynarr; Use the following functions/macros: void *Dynarr_new(type) [MACRO] Create a new dynamic-array object, with each element of the - specified type. The return value is a void * and must be cast to the - proper dynamic array type. + specified type. The return value is cast to (type##_dynarr). + This requires following the convention that types are declared in + such a way that this type concatenation works. In particular, TYPE + must be a symbol, not an arbitrary C type. Dynarr_add(d, el) [MACRO] Add an element to the end of a dynamic array. EL is a pointer @@ -76,6 +78,10 @@ int Dynarr_length(d) [MACRO] Return the number of elements currently in a dynamic array. + int Dynarr_largest(d) + [MACRO] Return the maximum value that Dynarr_length(d) would + ever have returned. + type Dynarr_at(d, i) [MACRO] Return the element at the specified index (no bounds checking done on the index). The element itself is returned, not a pointer @@ -108,9 +114,7 @@ void * Dynarr_newf (int elsize) { - Dynarr *d = (Dynarr *) xmalloc (sizeof (Dynarr)); - - memset (d, 0, sizeof (*d)); + Dynarr *d = xnew_and_zero (Dynarr); d->elsize = elsize; return d; @@ -229,4 +233,4 @@ return total; } -#endif +#endif /* MEMORY_USAGE_STATS */