mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 10:08:20 +00:00
Refactor SerializationFormat::EndWrite and ChunkedIO::Chunk mem mgmt.
SerializationFormat::EndWrite now transfers ownership of the buffer to the caller instead of doing a memcpy. ChunkedIO::Chunk is no longer a POD type, hopefully the ctor/dtor make it easier to manage its associated memory. It also now tracks how to deallocate its buffer (i.e. delete vs. free).
This commit is contained in:
parent
07a4a8d147
commit
70131b5c84
9 changed files with 87 additions and 77 deletions
|
@ -26,10 +26,27 @@ public:
|
|||
ChunkedIO();
|
||||
virtual ~ChunkedIO() { }
|
||||
|
||||
typedef struct {
|
||||
struct Chunk {
|
||||
typedef void (*FreeFunc)(char*);
|
||||
static void free_func_free(char* data) { free(data); }
|
||||
static void free_func_delete(char* data) { delete [] data; }
|
||||
|
||||
Chunk()
|
||||
: data(), len(), free_func(free_func_delete)
|
||||
{ }
|
||||
|
||||
Chunk(char* arg_data, uint32 arg_len,
|
||||
FreeFunc arg_ff = free_func_delete)
|
||||
: data(arg_data), len(arg_len), free_func(arg_ff)
|
||||
{ }
|
||||
|
||||
~Chunk()
|
||||
{ free_func(data); }
|
||||
|
||||
char* data;
|
||||
uint32 len;
|
||||
} Chunk;
|
||||
FreeFunc free_func;
|
||||
};
|
||||
|
||||
// Initialization before any I/O operation is performed. Returns false
|
||||
// on any form of error.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue