chiark
/
gitweb
/
~mdw
/
mLib
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add support for arena management.
[mLib]
/
darray.c
diff --git
a/darray.c
b/darray.c
index 83150f7c12ec52088213f1c1a4245f41b7b0d9c2..9e3eb905160bb3aa66f60798c76257d37aeebbcc 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.
5 2000/06/17 10:37:39
mdw Exp $
*
* Dynamically growing dense arrays
*
*
* Dynamically growing dense arrays
*
@@
-30,6
+30,9
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: darray.c,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: darray.c,v $
+ * 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
+54,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
+144,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);
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
+250,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
+290,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);