memalign.c
来自「spice中支持多层次元件模型仿真的可单独运行的插件源码」· C语言 代码 · 共 75 行
C
75 行
/* $Header: /home/harrison/c/tcgmsg/ipcv4.0/RCS/memalign.c,v 1.1 91/12/06 17:26:45 harrison Exp Locker: harrison $ */#if !defined(SUN) && !defined(CRAY)#if defined(ULTRIX) || defined(SGI) || defined(NEXT) || defined(HPUX)extern void *malloc();#else#ifndef IPSCextern char *malloc();#endif#endifchar *memalign(alignment, size) unsigned alignment; unsigned size;/* Cut from SUN man-page memalign() allocates size bytes on a specified alignment boundary, and returns a pointer to the allocated block. The value of the returned address is guaranteed to be an even multiple of alignment. Note: the value of alignment must be a power of two, and must be greater than or equal to the size of a word. No checking is done on the value of alignment ... should really.*/{ union screwup { unsigned long integer; char *address; } fiddle; unsigned long offset; alignment += alignment; /* Actually align on twice requested boundary */ fiddle.address = malloc((unsigned) (alignment+size)); if (fiddle.address != (char *) 0) { offset = fiddle.integer & (alignment-1); if (offset != 0) fiddle.address += alignment - offset; } return fiddle.address;}#endif#if defined(SUN)/* Use the system routine */void AvoidNullSymbolTable(){}#endif#if defined(CRAY)/* Alignment is not really an issue on the cray except when casting a character pointer to another type when information may be lost */extern char *malloc();char *memalign(alignment, size) unsigned alignment; unsigned size;{ return malloc(size);}#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?