chiark
/
gitweb
/
~mdw
/
mLib
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Ignore mlib-bin.
[mLib]
/
darray.c
diff --git
a/darray.c
b/darray.c
index 83150f7c12ec52088213f1c1a4245f41b7b0d9c2..c1ee606e3aef0e08d0472d7672db09810ab8b1fe 100644
(file)
--- a/
darray.c
+++ b/
darray.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: darray.c,v 1.
4 1999/11/06 12:40:45
mdw Exp $
+ * $Id: darray.c,v 1.
6 2000/07/16 12:29:16
mdw Exp $
*
* Dynamically growing dense arrays
*
*
* Dynamically growing dense arrays
*
@@
-30,6
+30,12
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: darray.c,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: darray.c,v $
+ * Revision 1.6 2000/07/16 12:29:16 mdw
+ * Change to arena `realloc' interface, to fix a design bug.
+ *
+ * Revision 1.5 2000/06/17 10:37:39 mdw
+ * Add support for arena management.
+ *
* Revision 1.4 1999/11/06 12:40:45 mdw
* Minor changes to allocation strategy.
*
* Revision 1.4 1999/11/06 12:40:45 mdw
* Minor changes to allocation strategy.
*
@@
-51,6
+57,7
@@
#include <stdlib.h>
#include "alloc.h"
#include <stdlib.h>
#include "alloc.h"
+#include "arena.h"
#include "darray.h"
/*----- Magic numbers -----------------------------------------------------*/
#include "darray.h"
/*----- Magic numbers -----------------------------------------------------*/
@@
-140,14
+147,14
@@
void *da_ensure(da_base *b, void *v, size_t sz, size_t n)
*/
if (p && slots == b->off) {
*/
if (p && slots == b->off) {
- q = x
realloc(p - b->off * sz, nsz * sz
);
+ q = x
_realloc(b->a, p - b->off * sz, nsz * sz, b->sz + b->off
);
q += slots * sz;
} else {
q += slots * sz;
} else {
- q = x
malloc(
nsz * sz);
+ q = x
_alloc(b->a,
nsz * sz);
q += slots * sz;
if (p) {
memcpy(q, p, b->len * sz);
q += slots * sz;
if (p) {
memcpy(q, p, b->len * sz);
-
free(
p - b->off * sz);
+
x_free(b->a,
p - b->off * sz);
}
}
}
}
@@
-246,11
+253,11
@@
void *da_shunt(da_base *b, void *v, size_t sz, size_t n)
* almost all the time -- that's the whole point of this routine!
*/
* almost all the time -- that's the whole point of this routine!
*/
- q = x
malloc(
nsz * sz);
+ q = x
_alloc(b->a,
nsz * sz);
q += (nsz - slots) * sz;
if (p) {
memcpy(q, p, b->len * sz);
q += (nsz - slots) * sz;
if (p) {
memcpy(q, p, b->len * sz);
-
free(
p - b->off * sz);
+
x_free(b->a,
p - b->off * sz);
}
/* --- Fill in the other parts of the base structure --- */
}
/* --- Fill in the other parts of the base structure --- */
@@
-286,13
+293,13
@@
void *da_tidy(da_base *b, void *v, size_t sz)
return (p);
if (!b->len) {
return (p);
if (!b->len) {
- free(p - b->off * sz);
+
x
free(p - b->off * sz);
return (0);
}
return (0);
}
- q = x
malloc(
b->len * sz);
+ q = x
_alloc(b->a,
b->len * sz);
memcpy(q, p, b->len * sz);
memcpy(q, p, b->len * sz);
-
free(
p - b->off * sz);
+
x_free(b->a,
p - b->off * sz);
b->sz = b->len;
b->off = 0;
return (q);
b->sz = b->len;
b->off = 0;
return (q);