diff options
Diffstat (limited to 'src/cc4group.h')
| -rw-r--r-- | src/cc4group.h | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/cc4group.h b/src/cc4group.h index e575a7e..0a3ceb4 100644 --- a/src/cc4group.h +++ b/src/cc4group.h @@ -136,6 +136,18 @@ typedef struct { typedef void* (*CC4Group_TmpMemoryStrategy)(CC4Group* const this, const size_t size, CC4Group_CleanupJob* cleanupJob); +// a memory management strategy +// actually, a memory management strategy is a pointer to an instance of this struct +// it consists of a start function (like allocating some memory and making a copy) +// and of an end function, which does the actual cleanup +// additionally to the predefined memory management strategies, custom strategies may be used +typedef struct { + void* (*start)(void* const data, const size_t size); + void (*end)(void* const data); +} const CC4Group_MemoryManagement_t; +typedef CC4Group_MemoryManagement_t* CC4Group_MemoryManagement; + + // callback types for openWithReadCallback // the callback has to store a pointer to the newly read data in data, as well as the amount of read data in size @@ -161,9 +173,9 @@ typedef bool (*CC4Group_WriteCallback)(const void* const data, size_t const size // it contains all available methods and constants typedef struct { struct { - int Take; // cc4group will free the data when its not needed anymore; e.g. in the destructor or when setting the file's data again - int Copy; // cc4group will copy the data to use it; the original data is untouched and needs to be freed by the caller whenever desired - int Reference; // cc4group will use the data as is (i.e. store the pointer and use it); the caller must guarantee it's validity throughout the groups lifetime (or until the file's data is set to a new pointer) and needs to take care of freeing it afterwards + CC4Group_MemoryManagement Take; // cc4group will free the data when its not needed anymore; e.g. in the destructor or when setting the file's data again + CC4Group_MemoryManagement Copy; // cc4group will copy the data to use it; the original data is untouched and needs to be freed by the caller whenever desired + CC4Group_MemoryManagement Reference; // cc4group will use the data as is (i.e. store the pointer and use it); the caller must guarantee it's validity throughout the groups lifetime (or until the file's data is set to a new pointer) and needs to take care of freeing it afterwards } const MemoryManagement; @@ -211,7 +223,7 @@ typedef struct { // see the description of MemoryManagement to know if and when data has to be freed by the caller // if the lazy mode is not used, the data can be freed immediately after this function returns // HINT: the lazy mode is actually not implemented yet, but at least I can't forget to mention it here anymore when it's actually done - bool (*openMemory)(CC4Group* const this, const void* const groupData, size_t const size, int const memoryManagement); + bool (*openMemory)(CC4Group* const this, const void* const groupData, size_t const size, CC4Group_MemoryManagement const memoryManagement); // opens a group through a file descriptor // the file descriptor must have been opened with read access and must be in blocking mode (should be default if O_NONBLOCK is not specified) @@ -226,7 +238,7 @@ typedef struct { // initCallback is called before readCallback is called and deinitCallback is called after all read operations are done // initCallback and deinitCallback may be NULL if they should not be used // even when using the Reference memory management, the buffer returned by the readCallback may be reused across callback calls - bool (*openWithReadCallback)(CC4Group* const this, CC4Group_ReadCallback const readCallback, void* const callbackArg, int const memoryManagement, CC4Group_ReadSetupCallback const initCallback, CC4Group_ReadSetupCallback const deinitCallback); + bool (*openWithReadCallback)(CC4Group* const this, CC4Group_ReadCallback const readCallback, void* const callbackArg, CC4Group_MemoryManagement const memoryManagement, CC4Group_ReadSetupCallback const initCallback, CC4Group_ReadSetupCallback const deinitCallback); // saves the current in-memory state of the group as a compressed c4group to disk @@ -287,7 +299,7 @@ typedef struct { // overwrites the data of the file denoted by entryPath with data indicated by data and size // see the description of MemoryManagement to know if and when data has to be freed by the caller - bool (*setEntryData)(CC4Group* const this, const char* const entryPath, const void* const data, size_t const size, int const memoryManagementMode); + bool (*setEntryData)(CC4Group* const this, const char* const entryPath, const void* const data, size_t const size, CC4Group_MemoryManagement const memoryManagementMode); // group metadata handling |
