How to allocate memory space without using malloc or new operator?

后端 未结 4 1436
礼貌的吻别
礼貌的吻别 2020-12-16 23:31

When my friend had his interview yesterday, he was asked a question: Implement a function that allocates memory space without using the *alloc or new operator, and the func

4条回答
  •  庸人自扰
    2020-12-17 00:10

    I think the question is more of a puzzle than a question that shows experience with programming. My solution would be allocating a global byte-array, that would be used instead of the heap:

    char heap[MAX_ALLOWED_MEM];
    
    /*
       The following function uses 'heap' as raw memory!
       void* like_malloc(size_t bytes);
       ...
    */
    

提交回复
热议问题