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

📄 psf2.h

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 H
字号:
#ifndef mpsf2_H
#define mpsf2_H

#ifndef mpsf1_H
#include "psf1.H"
#endif

#include <iostream.h>

/* 26th December, 1992 Mayan Moudgill.
   See pcf1.H for details
*/

template <size_t size>
class psfist_Imp {
private:
   static void *     _free_list;
public:
   static int        free();
   static int        free(unsigned);

   static
   inline void *     alloc(size_t sz)
      {
      void *  obj;
#ifdef BUG_CONFIRM
        cout << "alloc:   " << ( size & 1 ) << endl;
#endif
        (void) sz;
        if( _free_list == 0 ) {
           obj = malloc(size);              // is sz+sz%4 == size? it should.
        }
        else {
           obj = _free_list;
           _free_list = *((void **) obj); // Its not type safe--so what?
        }
        return obj;
      }
   static
   inline void       dealloc(void * obj)
      {
#ifdef BUG_CONFIRM
        cout << "dealloc: " << ( size & 1 ) << endl;
#endif
        *((void **) obj) = _free_list;
        _free_list = obj;                 // Neither is this--so what?
      }
};

template<class T>
void *    psfist<T>::operator new(size_t sz)
{
   return psfist_Imp<unsigned(sizeof(T))>::alloc(sz);
}

template<class T>
void      psfist<T>::operator delete(void * obj)
{
   psfist_Imp<unsigned(sizeof(T))>::dealloc(obj);
}

template<class T>
int       psfist<T>::free()
{
   return psfist_Imp<unsigned(sizeof(T))>::free();
}

template<class T>
int       psfist<T>::free(unsigned n)
{
   return psfist_Imp<unsigned(sizeof(T))>::free(n);
}

#include "psf2.c"

#endif

⌨️ 快捷键说明

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