blob: 7209bec01481c00bdb3b810ba9657f1c489938e0 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
Nicolas "Pixel" Noble1ff52d52015-03-01 05:24:36 +010034#ifndef GRPC_SUPPORT_ALLOC_H
35#define GRPC_SUPPORT_ALLOC_H
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080036
David Garcia Quintas6b114622016-07-27 14:49:53 -070037#include <stddef.h>
38
39#include <grpc/impl/codegen/port_platform.h>
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45typedef struct gpr_allocation_functions {
46 void *(*malloc_fn)(size_t size);
47 void *(*realloc_fn)(void *ptr, size_t size);
48 void (*free_fn)(void *ptr);
49} gpr_allocation_functions;
50
Craig Tillerf0da36b2016-10-10 13:07:37 -070051/* malloc.
52 * If size==0, always returns NULL. Otherwise this function never returns NULL.
53 * The pointer returned is suitably aligned for any kind of variable it could
54 * contain.
55 */
David Garcia Quintas6b114622016-07-27 14:49:53 -070056GPRAPI void *gpr_malloc(size_t size);
57/* free */
58GPRAPI void gpr_free(void *ptr);
59/* realloc, never returns NULL */
60GPRAPI void *gpr_realloc(void *p, size_t size);
61/* aligned malloc, never returns NULL, will align to 1 << alignment_log */
62GPRAPI void *gpr_malloc_aligned(size_t size, size_t alignment_log);
63/* free memory allocated by gpr_malloc_aligned */
64GPRAPI void gpr_free_aligned(void *ptr);
65
66/** Request the family of allocation functions in \a functions be used. NOTE
67 * that this request will be honored in a *best effort* basis and that no
68 * guarantees are made about the default functions (eg, malloc) being called. */
69GPRAPI void gpr_set_allocation_functions(gpr_allocation_functions functions);
70
71/** Return the family of allocation functions currently in effect. */
72GPRAPI gpr_allocation_functions gpr_get_allocation_functions();
73
74#ifdef __cplusplus
75}
76#endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080077
Craig Tillerd6c98df2015-08-18 09:33:44 -070078#endif /* GRPC_SUPPORT_ALLOC_H */