• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Révision1bc015efddaf7dc4ddd1b6b6831c43e7ad4582c0 (tree)
l'heure2018-02-01 03:48:29
AuteurWaldemar Brodkorb <wbx@ucli...>
CommiterWaldemar Brodkorb

Message de Log

malloc: add malloc_usable_size()

Change Summary

Modification

--- a/include/malloc.h
+++ b/include/malloc.h
@@ -162,6 +162,8 @@ extern int malloc_trim(size_t pad);
162162 /* Prints brief summary statistics on the stderr. */
163163 extern void malloc_stats(void);
164164
165+extern size_t malloc_usable_size(void *);
166+
165167 /* SVID2/XPG mallopt options */
166168 #ifndef M_MXFAST
167169 # define M_MXFAST 1 /* UNUSED in this malloc */
--- /dev/null
+++ b/libc/stdlib/malloc-standard/malloc_usable_size.c
@@ -0,0 +1,14 @@
1+/*
2+ malloc_usable_size - fully inspired by musl implementation
3+*/
4+
5+#include "malloc.h"
6+
7+/* for malloc_usable_size */
8+#define OVERHEAD (2*sizeof(size_t))
9+#define CHUNK_SIZE(c) ((c)->size & -2)
10+#define MEM_TO_CHUNK(p) (struct malloc_chunk *)((char *)(p) - OVERHEAD)
11+
12+size_t malloc_usable_size(void *p) {
13+ return p ? CHUNK_SIZE(MEM_TO_CHUNK(p)) - OVERHEAD : 0;
14+}