请教高手 一道据说是微软面试题

Assignment 1:

作业要求

    重载C++中的 operator new() operator delete()函数,为用户程序环境提供获得和释放批量动态空间函数接口;

详细描述

     对于一个自定义类,MyClass:

       Public class MyClass

       {
              public:

                     MyClass();

                     MyClass();

                     ….

}

重载void  * operator MyClass::new(size_t t)函数,实现分配批量MyClass对象的功能;这里的批量是自定义固定数目(可以用“#define NUM 100”语句来定义)。自定义new函数的功能是系统new函数功能的扩充,分配NUMMyClass大小的空间,这些空间可以是连续,也可以是分开的;如果分配失败,可以报错,再尝试分配,如果几次分配失败,抛出异常;内部实现可以用数组或链表来实现;

重载 void  operator MyClass::delete(void *)函数,实现对批量动态空间的回收;如果出现异常,返回错误;

实现一个函数,实现一个对Num个批量中的每一个MyClass对象的访问(如果是数组实现较简单,链表复杂些)

注:MyClass类可以采用

Class Student

{

      Public:

             Student();

             Student();

      Private:

       Char * firstName;

       Char * lastName;

       Int number;

}

评分标准

1.实现基本功能,符合题目要求;

2.如果采用链表来实现不连续动态空间分配,将酌情加分;

Assignment 2:

It's extremely important to avoid memory leak when developing in C++.

Using memory allocators written by yourself would be an alternative for this problem.

Now we need a FixedAllocator, which is able to allocate & free a block of memory at one time.

Its capability is fixed and initialized when initializing the allocator.

Try your best to design the class with some kind of machanism to solve memory leak problems.

And if you need to write other classes to support your design,go ahead. 

 

 

 

 

And the allocator is likely to be:

 

 

class FixedAllocator

{

  public:

       FixedAllocator(int blockSize,int blockCount);

       void* Alloc();

       void  Free(void*);

...............

...............

..............

};

 

 

Implementation of the three member functions above are a minimum requirement for the design.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值