📄 sc_alloc.h
字号:
/*------------------------------------------------------------------------------
$File: //hodad/usblink/3.4/source/os/lib/sc_alloc.h $
$DateTime: 2003/05/14 09:49:12 $
$Revision: #5 $
Purpose: SoftConnex memory allocation library used for allocating physically
aligned memory addresses or for general allocation of memory.
------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
CONFIDENTIAL AND PROPRIETARY INFORMATION OF SOFTCONNEX TECHNOLOGIES, INC.
THIS NOTICE IS NOT TO BE DELETED, MODIFIED, MOVED OR CHANGED IN ANY WAY.
Copyright (c) 1999 - 2003 by SoftConnex Technologies, Inc.
This software is protected by copyright laws and international copyright
treaties, as well as other intellectual property laws and treaties. This
software is a CONFIDENTIAL, unpublished work of authorship, and with portions
constituting TRADE SECRETS of SoftConnex Technologies, Inc., a Delaware USA
corporation. Any unauthorized use, disclosure, and/or reproduction of this
software, or any part of this software; or distribution of this software in any
form or by any means; or storage of this software in any database or retrieval
system, without the express written consent of, and license from, SoftConnex
Technologies, Inc. is strictly prohibited. This software is protected under the
copyright and/or trade secret laws in other countries in addition to USA. All
Rights Reserved. Failure to abide by the use, disclosure and/or reproduction
restrictions may result in civil and /or criminal penalties, and will be
prosecuted to the maximum extent of the law.
------------------------------------------------------------------------------*/
#ifndef _SOFTCONNEX_SC_ALLOC_H_
#define _SOFTCONNEX_SC_ALLOC_H_
/* In non-debug mode, the descriptor should be 16 bytes and in debug mode it
should be 32 bytes. Perfect sizes for the allocation scheme. */
typedef struct _MemoryDescriptor
{
void *start;
void *end;
struct _MemoryDescriptor *next;
#if USBLINK_DEBUG_MEMORY
U32 alignment;
char information[USBLINK_ALLOC_DEBUG_STRING];
#endif
} MemoryDescriptor;
/* These are the only alignments that we have needed so far (and then some).
Notice that the alignments are 32 bit long. This is assuming that pointer
size is 32 bits. The reason that the alignment values need to be the size of
the systems pointers is that the alignment value is added to and used as a
mask for the pointers to memory that are being passed back to the user. */
#define SC_NO_ALIGN ((U32) 0x00000000)
#define SC_ALIGN_2 ((U32) 0x00000001)
#define SC_ALIGN_4 ((U32) 0x00000003)
#define SC_ALIGN_8 ((U32) 0x00000007)
#define SC_ALIGN_16 ((U32) 0x0000000F)
#define SC_ALIGN_32 ((U32) 0x0000001F)
#define SC_ALIGN_64 ((U32) 0x0000002F)
#define SC_ALIGN_128 ((U32) 0x0000007F)
#define SC_ALIGN_256 ((U32) 0x000000FF)
#define SC_ALIGN_512 ((U32) 0x000001FF)
#define SC_ALIGN_1024 ((U32) 0x000003FF)
#define SC_ALIGN_2048 ((U32) 0x000007FF)
#define SC_ALIGN_4096 ((U32) 0x00000FFF)
/* These functions are the same no matter what build is done. */
SctStatus SC_MemoryPoolInitialize(void *newMemoryPool, U32 newPoolSize);
#if USBLINK_ENABLE_CLEANUP
SctStatus SC_MemoryPoolCleanup(void);
#else
#define SC_MemoryPoolCleanup() SCS_SUCCESS
#endif
void SC_Free(void *pointer);
/* if we are doing a project build in which we would like debug information
about our memory allocation, then we will allow strings to be passed in that
label what the allocation is for. */
#if USBLINK_DEBUG_MEMORY
void* SC_Malloc(U32 size, U32 alignment, char *string);
#define SC_SmartAlloc(size, alignment, string) \
SC_Malloc(size, alignment, string)
#define SC_SmartFree(pointer) SC_Free(pointer)
SctSemaphore GetMemorySemaphore(void);
MemoryDescriptor* GetHeadDescriptor(void);
MemoryDescriptor* GetLastDescriptor(void);
void* GetMemoryPoolStart(void);
void* GetMemoryPoolEnd(void);
U32 GetMemoryFree(void);
U32 GetMemorySize(void);
U32 GetMemoryDescriptorSize(void);
U32 GetNumberOfAllocations(void);
U32 GetMaxNumberOfAllocations(void);
U32 GetMaxMemoryAllocated(void);
void GetMetrics(U32 *total, U32 *fail, U32 *good);
#else /* DEBUG_MEMORY */
void* SC_Malloc(U32 size, U32 alignment);
#define SC_SmartAlloc(size, alignment, string) \
SC_Malloc(size, alignment)
#define SC_SmartFree(pointer) SC_Free(pointer)
#endif /* DEBUG_MEMORY */
#endif /* SOFTCONNEX_MEMORY_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -