⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 malloc-find.c

📁 内存分配的各种包装函数
💻 C
字号:
/* Find the starting address of a malloc'd block, from anywhere inside it.   Copyright (C) 1995 Free Software Foundation, Inc.This file is part of the GNU C Library.  Its master source is NOT part ofthe C library, however.  The master source lives in /gd/gnu/lib.The GNU C Library is free software; you can redistribute it and/ormodify it under the terms of the GNU Library General Public License aspublished by the Free Software Foundation; either version 2 of theLicense, or (at your option) any later version.The GNU C Library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNULibrary General Public License for more details.You should have received a copy of the GNU Library General PublicLicense along with the GNU C Library; see the file COPYING.LIB.  Ifnot, write to the Free Software Foundation, Inc., 675 Mass Ave,Cambridge, MA 02139, USA.  */#ifndef	_MALLOC_INTERNAL#define _MALLOC_INTERNAL#include <malloc.h>#endif/* Given an address in the middle of a malloc'd object,   return the address of the beginning of the object.  */__ptr_tmalloc_find_object_address (ptr)     __ptr_t ptr;{  __malloc_size_t block = BLOCK (ptr);  int type = _heapinfo[block].busy.type;  if (type == 0)    {      /* The object is one or more entire blocks.  */      __malloc_ptrdiff_t sizevalue = _heapinfo[block].busy.info.size;      if (sizevalue < 0)	/* This is one of the blocks after the first.  SIZEVALUE	   says how many blocks to go back to find the first.  */	block += sizevalue;      /* BLOCK is now the first block of the object.	 Its start is the start of the object.  */      return ADDRESS (block);    }  else    {      /* Get the size of fragments in this block.  */      __malloc_size_t size = 1 << type;      /* Turn off the low bits to find the start address of the fragment.  */      return _heapbase + (((char *) ptr - _heapbase) & ~(size - 1));    }}

⌨️ 快捷键说明

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