Commit 4302f80e authored by Robert Izzard's avatar Robert Izzard
Browse files

V1.51 restructed structures to save ~25% memory, other minor fixes/cleaning...

 V1.51 restructed structures to save ~25% memory, other minor fixes/cleaning of code, few extra subroutines to improve allocating memory.
parent ca8ac4f9
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -26,3 +26,5 @@
07/12/2023 : V1.41 fix citation typo and added a few recent papers that use libcdict (thanks to David Hendriks).

15/06/2024 : V1.5 added cdict_iter, an iterator for nested cdicts.

07/07/2024 : V1.51 restructed structures to save ~25% memory, other minor fixes/cleaning of code, few extra subroutines to improve allocating memory.
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
#include "cdict_prototypes.h"
#include "cdict_API.h"

#define CDICT_VERSION "1.5"
#define CDICT_VERSION "1.51"

/*
 * Global variables - very bad, I know, but these
+5 −6
Original line number Diff line number Diff line
@@ -114,8 +114,6 @@
        __CDict_new_from_,                      \
        CDICT_NARGS(__VA_ARGS__))(__VA_ARGS__)



/*
 * Call free on a pointer
 */
@@ -125,7 +123,7 @@
 * Turn on memory monitoring
 */
#define CDict_activate_memory_monitoring(CDICT)                     \
    (CDICT)->stats = malloc(sizeof(struct cdict_stats_t));  \
    cdict_alloc_stats_struct(CDICT);                                \
    (CDICT)->stats->malloc_count = 0;                               \
    (CDICT)->stats->calloc_count = 0;                               \
    (CDICT)->stats->realloc_count = 0;                              \
@@ -140,7 +138,6 @@
    (CDICT)->stats->pointer_list = NULL;                            \
    (CDICT)->stats->pointer_list_n = 0;


/*
 * CDict_set functions : set an element in the cdict
 */
@@ -229,10 +226,12 @@
/*
 * CDict_set_metadata : set an entry's metadata directly.
 */
#define CDict_set_metadata(ENTRY,                   \
#define CDict_set_metadata(CDICT,                   \
                           ENTRY,                   \
                           METADATA,                \
                           METADATA_FREE_FUNCTION)  \
    cdict_set_metadata((ENTRY),                     \
    cdict_set_metadata((CDICT),                     \
                       (ENTRY),                     \
                       (METADATA),                  \
                       (METADATA_FREE_FUNCTION))
/*
+0 −23
Original line number Diff line number Diff line
@@ -303,26 +303,3 @@ size_t cdict_total_alloced(struct cdict_t * const cdict,
    }
    return total;
}

void cdict_free_stats(struct cdict_t * const cdict)
{
    /*
     * Free stats memory : this can only be done
     * if the cdict is its own ancestor, and if cdict->stats
     * is allocated.
     */
    if(cdict != NULL &&
       cdict == cdict->ancestor &&
       cdict->stats != NULL)
    {
        for(size_t i=0; i<cdict->ancestor->stats->pointer_list_n; i++)
        {
            if(cdict->stats->pointer_list[i] != NULL)
            {
                free(cdict->stats->pointer_list[i]);
            }
        }
        free(cdict->stats->pointer_list);
        free(cdict->stats);
    }
}
+14 −0
Original line number Diff line number Diff line
#define _GNU_SOURCE
#include <stdio.h>
#include "cdict.h"

__CDict_Nonnull_some_arguments(1)
CDict_API_function
void cdict_alloc_stats_struct(struct cdict_t * const cdict)
{
    /*
     * Allocate memory for the cdict->stats structure
     */
    cdict->stats = __CDict_malloc(cdict,
                                  sizeof(struct cdict_stats_t));
}
Loading