summaryrefslogtreecommitdiff
path: root/src/common/ers.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/ers.h')
-rw-r--r--src/common/ers.h70
1 files changed, 35 insertions, 35 deletions
diff --git a/src/common/ers.h b/src/common/ers.h
index 51701d778..904f7fb81 100644
--- a/src/common/ers.h
+++ b/src/common/ers.h
@@ -13,16 +13,16 @@
* If it has reusable entries (freed entry), it uses one. *
* So no assumption should be made about the data of the entry. *
* Entries should be freed in the manager they where allocated from. *
- * Failure to do so can lead to unexpected behaviours. *
+ * Failure to do so can lead to unexpected behaviors. *
* *
* <H2>Advantages:</H2> *
* - The same manager is used for entries of the same size. *
* So entries freed in one instance of the manager can be used by other *
* instances of the manager. *
* - Much less memory allocation/deallocation - program will be faster. *
- * - Avoids memory fragmentaion - program will run better for longer. *
+ * - Avoids memory fragmentation - program will run better for longer. *
* *
- * <H2>Disavantages:</H2> *
+ * <H2>Disadvantages:</H2> *
* - Unused entries are almost inevitable - memory being wasted. *
* - A manager will only auto-destroy when all of its instances are *
* destroyed so memory will usually only be recovered near the end. *
@@ -37,8 +37,8 @@
* @author Flavio @ Amazon Project *
* @encoding US-ASCII *
\*****************************************************************************/
-#ifndef _ERS_H_
-#define _ERS_H_
+#ifndef COMMON_ERS_H
+#define COMMON_ERS_H
#include "../common/cbasetypes.h"
@@ -49,13 +49,13 @@
* ERS - Entry manager. *
* ers_new - Allocate an instance of an entry manager. *
* ers_report - Print a report about the current state. *
- * ers_force_destroy_all - Force the destruction of all the managers. *
+ * ers_final - Clears the remainder of the managers. *
\*****************************************************************************/
/**
* Define this to disable the Entry Reusage System.
* All code except the typedef of ERInterface will be disabled.
- * To allow a smooth transition,
+ * To allow a smooth transition,
*/
//#define DISABLE_ERS
@@ -63,18 +63,23 @@
* Entries are aligned to ERS_ALIGNED bytes in the blocks of entries.
* By default it aligns to one byte, using the "natural order" of the entries.
* This should NEVER be set to zero or less.
- * If greater than one, some memory can be wasted. This should never be needed
- * but is here just in case some aligment issues arise.
+ * If greater than one, some memory can be wasted. This should never be needed
+ * but is here just in case some alignment issues arise.
*/
#ifndef ERS_ALIGNED
# define ERS_ALIGNED 1
#endif /* not ERS_ALIGN_ENTRY */
enum ERSOptions {
- ERS_OPT_NONE = 0x0,
- ERS_OPT_CLEAR = 0x1,/* silently clears any entries left in the manager upon destruction */
- ERS_OPT_WAIT = 0x2,/* wait for entries to come in order to list! */
- ERS_OPT_FREE_NAME = 0x4,/* name is dynamic memory, and should be freed */
+ ERS_OPT_NONE = 0x0,
+ ERS_OPT_CLEAR = 0x1,/* silently clears any entries left in the manager upon destruction */
+ ERS_OPT_WAIT = 0x2,/* wait for entries to come in order to list! */
+ ERS_OPT_FREE_NAME = 0x4,/* name is dynamic memory, and should be freed */
+ ERS_OPT_CLEAN = 0x8,/* clears used memory upon ers_free so that its all new to be reused on the next alloc */
+ ERS_OPT_FLEX_CHUNK = 0x10,/* signs that it should look for its own cache given it'll have a dynamic chunk size, so that it doesn't affect the other ERS it'd otherwise be sharing */
+
+ /* Compound, is used to determine whether it should be looking for a cache of matching options */
+ ERS_CACHE_OPTIONS = ERS_OPT_CLEAN|ERS_OPT_FLEX_CHUNK,
};
/**
@@ -97,7 +102,7 @@ typedef struct eri {
/**
* Free an entry allocated from this manager.
* WARNING: Does not check if the entry was allocated by this manager.
- * Freeing such an entry can lead to unexpected behaviour.
+ * Freeing such an entry can lead to unexpected behavior.
* @param self Interface of the entry manager
* @param entry Entry to be freed
*/
@@ -113,7 +118,7 @@ typedef struct eri {
/**
* Destroy this instance of the manager.
* The manager is actually only destroyed when all the instances are destroyed.
- * When destroying the manager a warning is shown if the manager has
+ * When destroying the manager a warning is shown if the manager has
* missing/extra entries.
* @param self Interface of the entry manager
*/
@@ -121,7 +126,7 @@ typedef struct eri {
/* */
void (*chunk_size) (struct eri *self, unsigned int new_size);
-} *ERS;
+} ERS;
#ifdef DISABLE_ERS
// Use memory manager to allocate/free and disable other interface functions
@@ -133,27 +138,27 @@ typedef struct eri {
// Disable the public functions
# define ers_new(size,name,options) NULL
# define ers_report()
-# define ers_force_destroy_all()
+# define ers_final()
#else /* not DISABLE_ERS */
-// These defines should be used to allow the code to keep working whenever
+// These defines should be used to allow the code to keep working whenever
// the system is disabled
-# define ers_alloc(obj,type) (type *)(obj)->alloc(obj)
-# define ers_free(obj,entry) (obj)->free((obj),(entry))
-# define ers_entry_size(obj) (obj)->entry_size(obj)
-# define ers_destroy(obj) (obj)->destroy(obj)
-# define ers_chunk_size(obj,size) (obj)->chunk_size(obj,size)
+# define ers_alloc(obj,type) ((type *)(obj)->alloc(obj))
+# define ers_free(obj,entry) ((obj)->free((obj),(entry)))
+# define ers_entry_size(obj) ((obj)->entry_size(obj))
+# define ers_destroy(obj) ((obj)->destroy(obj))
+# define ers_chunk_size(obj,size) ((obj)->chunk_size((obj),(size)))
/**
* Get a new instance of the manager that handles the specified entry size.
* Size has to greater than 0.
- * If the specified size is smaller than a pointer, the size of a pointer is
+ * If the specified size is smaller than a pointer, the size of a pointer is
* used instead.
- * It's also aligned to ERS_ALIGNED bytes, so the smallest multiple of
+ * It's also aligned to ERS_ALIGNED bytes, so the smallest multiple of
* ERS_ALIGNED that is greater or equal to size is what's actually used.
* @param The requested size of the entry in bytes
* @return Interface of the object
*/
-ERS ers_new(uint32 size, char *name, enum ERSOptions options);
+ERS *ers_new(uint32 size, char *name, enum ERSOptions options);
/**
* Print a report about the current state of the Entry Reusage System.
@@ -165,14 +170,9 @@ ERS ers_new(uint32 size, char *name, enum ERSOptions options);
void ers_report(void);
/**
- * Forcibly destroy all the entry managers, checking for nothing.
- * The system is left as if no instances or entries had ever been allocated.
- * All previous entries and instances of the managers become invalid.
- * The use of this is NOT recommended.
- * It should only be used in extreme situations to make shure all the memory
- * allocated by this system is released.
- */
-void ers_force_destroy_all(void);
+ * Clears the remainder of the managers
+ **/
+void ers_final(void);
#endif /* DISABLE_ERS / not DISABLE_ERS */
-#endif /* _ERS_H_ */
+#endif /* COMMON_ERS_H */