Memory management by c program, C/C++ Programming

Memory management by c program:

Write a program to memory management in c program

unsigned max( unsigned, unsigned );

 

int BaseMemBlocks::allocBlock( size_t sz )

{

    BlockList _FAR *temp = new( max(sz,blockSize) ) BlockList( curBlock-1 );

    if( temp == 0 )

        return 0;

    curBlock = temp+1;

    blockCount++;

    return 1;

}

 

void BaseMemBlocks::freeTo( unsigned term )

{

    PRECONDITION( blockCount >= term );

    while( blockCount > term )

        {

        BlockList _FAR *temp = curBlock-1;

        curBlock = (temp->next)+1;

        delete temp;

        blockCount--;

        }

}

 

void _FAR *MemStack::allocate( size_t sz )

{

    sz = max( 1, sz );

    if( sz > blockSize - curLoc )

        if( allocBlock( sz ) == 0 )

            return 0;

        else

            curLoc = 0;

    void _FAR *temp = block() + curLoc;

    curLoc += sz;

    return temp;

}

Posted Date: 10/19/2012 2:58:43 AM | Location : United States







Related Discussions:- Memory management by c program, Assignment Help, Ask Question on Memory management by c program, Get Answer, Expert's Help, Memory management by c program Discussions

Write discussion on Memory management by c program
Your posts are moderated
Related Questions
Aim: To implement a program to swap two numbers using reference arguments. Code: void swap(int *a, int *b) {             int temp;             temp=*a;

write a c++ program for minimum shelf downloads

padovan string program 1 : package test.padovanstring; public class PadovanString {     public int stringOccurrences(int n, String str){        if(n >= 40)     return -

A: auto: the default. Variables are created and initialized automatically while they are defined and destroyed at the ending of the block containing their definition. They are not

in this problem you are given a board in which some of the elements are placed as shown in below diagram.each element represent a color.fill the other element in the board,such tha

Give practice in writing program''s..

What is the difference among malloc/free and new/delete? A: Malloc/free do not know about destructors and constructors. New & delete create and destroy objects, whereas malloc &

Example of structure: struct item {                 int element;                 node_ptr next; }; typedef node_ptr stack; stack create(void) {

Need assignment help What's the order that local objects are destructed?

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome