n += sizeof(size_t);
ptr = &((size_t *) ptr)[-1];
mem_used = mem_used - *((size_t *) ptr) + n;
+#endif
+#if defined(M_SIZE)
+#if ENABLE_POISONING
+ {
+ uint64_t *base = ptr;
+ size_t s = M_SIZE (ptr);
+
+ if (s > n)
+ {
+ const uint64_t baadfood = GNUNET_ntohll (0xBAADF00DBAADF00DLL);
+ char *cbase = ptr;
+
+ GNUNET_memcpy (&cbase[n],
+ &baadfood,
+ GNUNET_MIN (8 - (n % 8),
+ s - n));
+ for (size_t i = 1 + (n + 7) / 8; i < s / 8; i++)
+ base[i] = baadfood;
+ GNUNET_memcpy (&base[s / 8],
+ &baadfood,
+ s % 8);
+ }
+ }
+#endif
#endif
ptr = realloc (ptr, n);
if ((NULL == ptr) && (n > 0))
const uint64_t baadfood = GNUNET_ntohll (0xBAADF00DBAADF00DLL);
uint64_t *base = ptr;
size_t s = M_SIZE (ptr);
- size_t i;
- for (i = 0; i < s / 8; i++)
+ for (size_t i = 0; i < s / 8; i++)
base[i] = baadfood;
GNUNET_memcpy (&base[s / 8], &baadfood, s % 8);
}
#include <gauger.h>
static uint64_t
-perfMalloc ()
+perf_malloc ()
{
- size_t i;
uint64_t ret;
ret = 0;
- for (i = 1; i < 1024 * 1024; i += 1024)
+ for (size_t i = 1; i < 1024 * 1024; i += 1024)
{
ret += i;
GNUNET_free (GNUNET_malloc (i));
}
+static uint64_t
+perf_realloc ()
+{
+ uint64_t ret;
+
+ ret = 0;
+ for (size_t i = 10; i < 1024 * 1024 / 5; i += 1024)
+ {
+ char *ptr;
+
+ ret += i;
+ ptr = GNUNET_malloc (i);
+ memset (ptr, 1, i);
+ ptr = GNUNET_realloc (ptr, i + 5);
+ for (size_t j=0;j<i;j++)
+ GNUNET_assert (1 == ptr[j]);
+ memset (ptr, 6, i + 5);
+ ptr = GNUNET_realloc (ptr, i - 5);
+ for (size_t j=0;j<i-5;j++)
+ GNUNET_assert (6 == ptr[j]);
+ GNUNET_free (ptr);
+ }
+ return ret;
+}
+
+
int
main (int argc, char *argv[])
{
uint64_t kb;
start = GNUNET_TIME_absolute_get ();
- kb = perfMalloc ();
+ kb = perf_malloc ();
printf ("Malloc perf took %s\n",
GNUNET_STRINGS_relative_time_to_string (
GNUNET_TIME_absolute_get_duration (start),
kb / 1024 / (1
+ GNUNET_TIME_absolute_get_duration
(start).rel_value_us / 1000LL), "kb/ms");
+ start = GNUNET_TIME_absolute_get ();
+ kb = perf_realloc ();
+ printf ("Realloc perf took %s\n",
+ GNUNET_STRINGS_relative_time_to_string (
+ GNUNET_TIME_absolute_get_duration (start),
+ GNUNET_YES));
return 0;
}