malloc16.c

来自「gnuradio软件无线电源程序.现在的手机多基于软件无线电」· C语言 代码 · 共 47 行

C
47
字号
/* Wrapper functions for malloc/free that force 16-byte alignment * See http://perso.club-internet.fr/matmac/sourcesc.htm * Copyright 2001 Phil Karn, KA9Q * May be used under the terms of the GNU Public License (GPL) */#include "malloc16.h"#include <string.h>void *malloc16Align(int size){  void *p;  void **p1;  if((p = malloc(size+31)) == NULL)    return NULL;  /* Round up to next 16-byte boundary */  p1 = (void **)(((int)p + 31) & (~15));  /* Stash actual start of block just before ptr we return */  p1[-1] = p;  /* Return 16-byte aligned address */  return (void *)p1;}void *calloc16Align(size_t nmemb,size_t size){  int nbytes;  void *p;  nbytes = nmemb*size;  if((p = malloc16Align(nbytes)) == NULL)    return NULL;  memset(p,0,nbytes);  return p;}void free16Align(void *p){  if(p != NULL){    /* Retrieve pointer to actual start of block and free it */    free(((void **)p)[-1]);  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?