Lots more work on eng::malloc

This commit is contained in:
2022-02-28 21:57:54 -05:00
parent ff932dba10
commit 7cd8eb0a43
25 changed files with 314 additions and 253 deletions

View File

@@ -1,6 +1,6 @@
#include "wrap-string.hpp"
#include "two-mallocs.hpp"
#include "eng-malloc.hpp"
#include "streambuffer.hpp"
#include "spookyv2.hpp"
@@ -25,7 +25,7 @@ StreamBuffer::StreamBuffer() {
StreamBuffer::StreamBuffer(int64_t size, bool fixed) {
assert(size >= 0);
init(fixed, true, (char*)dlmalloc(size), size);
init(fixed, true, (char*)eng::malloc(size), size);
}
StreamBuffer::StreamBuffer(const char *s, int64_t size) {
@@ -40,7 +40,7 @@ StreamBuffer::StreamBuffer(const eng::string &src) {
}
StreamBuffer::~StreamBuffer() {
if (owned_ && (buf_lo_ != 0)) dlfree(buf_lo_);
if (owned_ && (buf_lo_ != 0)) eng::free(buf_lo_);
}
int64_t StreamBuffer::total_reads() const {
@@ -87,9 +87,9 @@ void StreamBuffer::make_space_slow(int64_t bytes) {
} else if (existing_size >= desired_size) {
if (data_size > 0) memcpy(buf_lo_, read_cursor_, data_size);
} else {
char *nbuf = (char *)dlmalloc(desired_size);
char *nbuf = (char *)eng::malloc(desired_size);
if (data_size > 0) memcpy(nbuf, read_cursor_, data_size);
if (buf_lo_ != nullptr) dlfree(buf_lo_);
if (buf_lo_ != nullptr) eng::free(buf_lo_);
buf_lo_ = nbuf;
buf_hi_ = nbuf + desired_size;
}
@@ -116,7 +116,7 @@ char *StreamBuffer::get_overwrite(int64_t size, int64_t write_count_after) {
void StreamBuffer::clear() {
assert(owned_);
if (!fixed_size_) {
if (buf_lo_ != nullptr) dlfree(buf_lo_);
if (buf_lo_ != nullptr) eng::free(buf_lo_);
buf_lo_ = 0;
buf_hi_ = 0;
}