diff options
author | Thomas Haller <thaller@redhat.com> | 2020-07-13 23:40:46 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-07-13 23:40:48 +0200 |
commit | 7b14686ae2b0d610661af1958062c5388c0cb6bf (patch) | |
tree | fc9be8c6b5758ca10fd59d28549f46d8a44f68a8 /shared/nm-std-aux/nm-std-utils.h | |
parent | 8582a5f356b758b9fc44f977fbad10132fcbd926 (diff) | |
parent | 5542275672672299860117f6cc3c5b8e234bd8dc (diff) | |
download | NetworkManager-1.27.1-dev.tar.gz |
release: bump version to 1.27.1 (development)1.27.1-dev
Diffstat (limited to 'shared/nm-std-aux/nm-std-utils.h')
-rw-r--r-- | shared/nm-std-aux/nm-std-utils.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/shared/nm-std-aux/nm-std-utils.h b/shared/nm-std-aux/nm-std-utils.h new file mode 100644 index 0000000000..0945c8600f --- /dev/null +++ b/shared/nm-std-aux/nm-std-utils.h @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: LGPL-2.1+ + +#ifndef __NM_STD_UTILS_H__ +#define __NM_STD_UTILS_H__ + +#include <stdbool.h> + +#include "nm-std-aux.h" + +/*****************************************************************************/ + +/* nm_utils_get_next_realloc_size() is used to grow buffers exponentially, when + * the final size is unknown. As such, it has borders for which it allocates + * certain buffer sizes. + * + * The use of these defines is to get favorable allocation sequences. + * For example, nm_str_buf_init() asks for an initial allocation size. Note that + * it reserves the exactly requested amount, under the assumption that the + * user may know how many bytes will be required. However, often the caller + * doesn't know in advance, and NMStrBuf grows exponentially by calling + * nm_utils_get_next_realloc_size(). + * Imagine you call nm_str_buf_init() with an initial buffer size 100, and you + * add one character at a time. Then the first reallocation will increase the + * buffer size only from 100 to 104. + * If you however start with an initial buffer size of 104, then the next reallocation + * via nm_utils_get_next_realloc_size() gives you 232, and so on. By using + * these sizes, it results in one less allocation, if you anyway don't know the + * exact size in advance. */ +#define NM_UTILS_GET_NEXT_REALLOC_SIZE_32 ((size_t) 32) +#define NM_UTILS_GET_NEXT_REALLOC_SIZE_40 ((size_t) 40) +#define NM_UTILS_GET_NEXT_REALLOC_SIZE_104 ((size_t) 104) +#define NM_UTILS_GET_NEXT_REALLOC_SIZE_1000 ((size_t) 1000) + +size_t nm_utils_get_next_realloc_size (bool true_realloc, size_t requested); + +#endif /* __NM_STD_UTILS_H__ */ |