Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:36

0001 /*
0002  * Copyright (C) the libgit2 contributors. All rights reserved.
0003  *
0004  * This file is part of libgit2, distributed under the GNU GPL v2 with
0005  * a Linking Exception. For full terms see the included COPYING file.
0006  */
0007 
0008 #ifndef INCLUDE_sys_git_alloc_h__
0009 #define INCLUDE_sys_git_alloc_h__
0010 
0011 #include "git2/common.h"
0012 
0013 GIT_BEGIN_DECL
0014 
0015 /**
0016  * An instance for a custom memory allocator
0017  *
0018  * Setting the pointers of this structure allows the developer to implement
0019  * custom memory allocators. The global memory allocator can be set by using
0020  * "GIT_OPT_SET_ALLOCATOR" with the `git_libgit2_opts` function. Keep in mind
0021  * that all fields need to be set to a proper function.
0022  */
0023 typedef struct {
0024     /** Allocate `n` bytes of memory */
0025     void * GIT_CALLBACK(gmalloc)(size_t n, const char *file, int line);
0026 
0027     /**
0028      * This function shall deallocate the old object `ptr` and return a
0029      * pointer to a new object that has the size specified by `size`. In
0030      * case `ptr` is `NULL`, a new array shall be allocated.
0031      */
0032     void * GIT_CALLBACK(grealloc)(void *ptr, size_t size, const char *file, int line);
0033 
0034     /**
0035      * This function shall free the memory pointed to by `ptr`. In case
0036      * `ptr` is `NULL`, this shall be a no-op.
0037      */
0038     void GIT_CALLBACK(gfree)(void *ptr);
0039 } git_allocator;
0040 
0041 /**
0042  * Initialize the allocator structure to use the `stdalloc` pointer.
0043  *
0044  * Set up the structure so that all of its members are using the standard
0045  * "stdalloc" allocator functions. The structure can then be used with
0046  * `git_allocator_setup`.
0047  *
0048  * @param allocator The allocator that is to be initialized.
0049  * @return An error code or 0.
0050  */
0051 int git_stdalloc_init_allocator(git_allocator *allocator);
0052 
0053 /**
0054  * Initialize the allocator structure to use the `crtdbg` pointer.
0055  *
0056  * Set up the structure so that all of its members are using the "crtdbg"
0057  * allocator functions. Note that this allocator is only available on Windows
0058  * platforms and only if libgit2 is being compiled with "-DMSVC_CRTDBG".
0059  *
0060  * @param allocator The allocator that is to be initialized.
0061  * @return An error code or 0.
0062  */
0063 int git_win32_crtdbg_init_allocator(git_allocator *allocator);
0064 
0065 GIT_END_DECL
0066 
0067 #endif