|
@@ -16,7 +16,7 @@ void asInit(Arrays* as) {
|
|
|
|
|
|
void asDelete(Arrays* as) {
|
|
void asDelete(Arrays* as) {
|
|
for(int i = 0; i < as->capacity; i++) {
|
|
for(int i = 0; i < as->capacity; i++) {
|
|
- allocatedBytes -= as->data[i].length * as->data[i].typeSize;
|
|
|
|
|
|
+ allocatedBytes -= as->data[i].size;
|
|
free(as->data[i].data);
|
|
free(as->data[i].data);
|
|
}
|
|
}
|
|
allocatedBytes -= as->capacity * sizeof(Array);
|
|
allocatedBytes -= as->capacity * sizeof(Array);
|
|
@@ -24,8 +24,8 @@ void asDelete(Arrays* as) {
|
|
}
|
|
}
|
|
|
|
|
|
static void aInitArray(Array* a, int previous, int next) {
|
|
static void aInitArray(Array* a, int previous, int next) {
|
|
|
|
+ a->size = 0;
|
|
a->length = 0;
|
|
a->length = 0;
|
|
- a->typeSize = 0;
|
|
|
|
a->next = next;
|
|
a->next = next;
|
|
a->previous = previous;
|
|
a->previous = previous;
|
|
a->data = NULL;
|
|
a->data = NULL;
|
|
@@ -63,9 +63,9 @@ static void asPrintDebug(Arrays* as) {
|
|
printf("Free: %d, Used: %d\n", as->freeStart, as->usedStart);
|
|
printf("Free: %d, Used: %d\n", as->freeStart, as->usedStart);
|
|
for(int i = 0; i < as->capacity; i++) {
|
|
for(int i = 0; i < as->capacity; i++) {
|
|
Array* a = as->data + i;
|
|
Array* a = as->data + i;
|
|
- printf("%d: %s, length: %d, next: %d, previous: %d, size: %d\n", i,
|
|
|
|
- a->data == NULL ? "null" : "valid", a->length, a->next,
|
|
|
|
- a->previous, a->typeSize);
|
|
|
|
|
|
+ printf("%d: %s, size: %d, next: %d, previous: %d\n", i,
|
|
|
|
+ a->data == NULL ? "null" : "valid", a->size, a->next,
|
|
|
|
+ a->previous);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -96,14 +96,14 @@ int asAllocate(Arrays* as, int typeSize, int length) {
|
|
}
|
|
}
|
|
as->usedStart = index;
|
|
as->usedStart = index;
|
|
|
|
|
|
|
|
+ array->size = bytes;
|
|
array->length = length;
|
|
array->length = length;
|
|
- array->typeSize = typeSize;
|
|
|
|
array->data = malloc(bytes);
|
|
array->data = malloc(bytes);
|
|
return index;
|
|
return index;
|
|
}
|
|
}
|
|
|
|
|
|
Array* asGet(Arrays* as, int p) {
|
|
Array* asGet(Arrays* as, int p) {
|
|
- if(p < 0 || p >= as->capacity || as->data[p].typeSize == 0) {
|
|
|
|
|
|
+ if(p < 0 || p >= as->capacity || as->data[p].size == 0) {
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
return as->data + p;
|
|
return as->data + p;
|
|
@@ -128,10 +128,10 @@ void asDeleteArray(Arrays* as, Array* a, int p) {
|
|
}
|
|
}
|
|
as->freeStart = p;
|
|
as->freeStart = p;
|
|
|
|
|
|
- allocatedBytes -= a->typeSize * a->length;
|
|
|
|
|
|
+ allocatedBytes -= a->size;
|
|
a->previous = -1;
|
|
a->previous = -1;
|
|
|
|
+ a->size = 0;
|
|
a->length = 0;
|
|
a->length = 0;
|
|
- a->typeSize = 0;
|
|
|
|
free(a->data);
|
|
free(a->data);
|
|
a->data = NULL;
|
|
a->data = NULL;
|
|
}
|
|
}
|