diff options
author | Max Kellermann <max@duempel.org> | 2008-08-29 09:39:08 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-08-29 09:39:08 +0200 |
commit | 1aa3457346b6c88d4d43e6faf5cde2ae95f36275 (patch) | |
tree | c34d6f76e5cb724711737432179342198c5b4f91 /src/tag.h | |
parent | 031522060aa64fea48e30480bee9b5daa3737089 (diff) | |
download | mpd-1aa3457346b6c88d4d43e6faf5cde2ae95f36275.tar.gz mpd-1aa3457346b6c88d4d43e6faf5cde2ae95f36275.tar.xz mpd-1aa3457346b6c88d4d43e6faf5cde2ae95f36275.zip |
tag: try not to reallocate tag.items in every add() call
If many tag_items are added at once while the tag cache is being
loaded, manage these items in a static fixed list, instead of
reallocating the list with every newly created item. This reduces
heap fragmentation.
Massif results again:
mk before: total 12,837,632; useful 10,626,383; extra 2,211,249
mk now: total 12,736,720; useful 10,626,383; extra 2,110,337
The "useful" value is the same since this patch only changes the way
we allocate the same amount of memory, but heap fragmentation was
reduced by 5%.
Diffstat (limited to 'src/tag.h')
-rw-r--r-- | src/tag.h | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -61,8 +61,22 @@ void tag_clear_items_by_type(struct tag *tag, enum tag_type itemType); void tag_free(struct tag *tag); +/** + * Gives an optional hint to the tag library that we will now add + * several tag items; this is used by the library to optimize memory + * allocation. Only one tag may be in this state, and this tag must + * not have any items yet. You must call tag_end_add() when you are + * done. + */ +void tag_begin_add(struct tag *tag); + +/** + * Finishes the operation started with tag_begin_add(). + */ +void tag_end_add(struct tag *tag); + void tag_add_item_n(struct tag *tag, enum tag_type itemType, - const char *value, size_t len); + const char *value, size_t len); static inline void tag_add_item(struct tag *tag, enum tag_type itemType, const char *value) |