| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | //  MNNMemoryUtils.h
 | 
					
						
							|  |  |  | //  MNN
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Created by MNN on 2018/07/14.
 | 
					
						
							|  |  |  | //  Copyright © 2018, Alibaba Group Holding Limited
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef MNNMemoryUtils_h
 | 
					
						
							|  |  |  | #define MNNMemoryUtils_h
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							| 
									
										
										
										
											2019-12-27 22:16:57 +08:00
										 |  |  | #include "core/Macro.h"
 | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-12 11:34:45 +08:00
										 |  |  | #define MNN_MEMORY_ALIGN_DEFAULT 64
 | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief alloc memory with given size & alignment. | 
					
						
							|  |  |  |  * @param size  given size. size should > 0. | 
					
						
							|  |  |  |  * @param align given alignment. | 
					
						
							|  |  |  |  * @return memory pointer. | 
					
						
							|  |  |  |  * @warning use `MNNMemoryFreeAlign` to free returned pointer. | 
					
						
							|  |  |  |  * @sa MNNMemoryFreeAlign | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-08-22 20:13:46 +08:00
										 |  |  | MNN_PUBLIC void* MNNMemoryAllocAlign(size_t size, size_t align); | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief alloc memory with given size & alignment, and fill memory space with 0. | 
					
						
							|  |  |  |  * @param size  given size. size should > 0. | 
					
						
							|  |  |  |  * @param align given alignment. | 
					
						
							|  |  |  |  * @return memory pointer. | 
					
						
							|  |  |  |  * @warning use `MNNMemoryFreeAlign` to free returned pointer. | 
					
						
							|  |  |  |  * @sa MNNMemoryFreeAlign | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-08-22 20:13:46 +08:00
										 |  |  | MNN_PUBLIC void* MNNMemoryCallocAlign(size_t size, size_t align); | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief free aligned memory pointer. | 
					
						
							|  |  |  |  * @param mem   aligned memory pointer. | 
					
						
							|  |  |  |  * @warning do NOT pass any pointer NOT returned by `MNNMemoryAllocAlign` or `MNNMemoryCallocAlign`. | 
					
						
							|  |  |  |  * @sa MNNMemoryAllocAlign | 
					
						
							|  |  |  |  * @sa MNNMemoryCallocAlign | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-08-22 20:13:46 +08:00
										 |  |  | MNN_PUBLIC void MNNMemoryFreeAlign(void* mem); | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* MNNMemoryUtils_h */
 |