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

📄 defalloc.cpp

📁 含有多种公开密钥算法、多种块加密、多种数据流加密、多种HASH函数、多种CheckSum校验、多种MAC校验等几十种加密算法的程序
💻 CPP
字号:
/************************************************** Default Allocator Source File                  ** (C) 1999-2002 The Botan Project                **************************************************/#include <botan/defalloc.h>#include <cstdlib>#include <cstring>namespace Botan {/************************************************** Allocation                                     **************************************************/void* Default_Allocator::alloc_block(u32bit n) const   {   if(n == PREF_SIZE)      {      for(u32bit j = 0; j != CACHE_SIZE; j++)         if(cache[j])            {            void* ptr = cache[j];            cache[j] = 0;            std::memset(ptr, 0, n);            return ptr;            }      }   void* ptr = std::malloc(n);   if(ptr)      std::memset(ptr, 0, n);   return ptr;   }/************************************************** Deallocation                                   **************************************************/void Default_Allocator::dealloc_block(void* ptr, u32bit n) const   {   if(n == PREF_SIZE)      {      for(u32bit j = 0; j != CACHE_SIZE; j++)         if(cache[j] == 0)            {            cache[j] = ptr;            return;            }      }   std::memset(ptr, 0, n);   std::free(ptr);   }/************************************************** Constructor                                    **************************************************/Default_Allocator::Default_Allocator() : ManagedAllocator(true, PREF_SIZE)   {   for(u32bit j = 0; j != CACHE_SIZE; j++)      {      cache[j] = std::malloc(PREF_SIZE);      if(!cache[j])         throw Memory_Exhaustion();      std::memset(cache[j], 0, PREF_SIZE);      }   }/************************************************** Destructor                                     **************************************************/Default_Allocator::~Default_Allocator()   {   for(u32bit j = 0; j != CACHE_SIZE; j++)      if(cache[j])         {         std::memset(cache[j], 0, PREF_SIZE);         std::free(cache[j]);         }   }}

⌨️ 快捷键说明

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