Re: There seems to be a problem with Assignment 3!


[ Follow Ups ] [ Post Followup ] [ CCNY CSc 212 Messages ] [ Help ]

Posted by Here's another Problem.. on October 12, 2002 at 10:11:00:

In Reply to: Re: There seems to be a problem with Assignment 3! posted by Rob on October 12, 2002 at 01:20:20:

D:\MyProjectsUpdated\Assignment 3\sequence2.cpp(80) : error C2629: unexpected 'unsigned int ('
D:\MyProjectsUpdated\Assignment 3\sequence2.cpp(81) : error C2809: 'operator new' has no formal parameters
D:\MyProjectsUpdated\Assignment 3\sequence2.cpp(90) : error C2065: 'size' : undeclared identifier

void* operator new(unsigned(sequence::size_type size))
{
char *whole_block; // Pointer to the entire block that we get from heap
sequence::size_type *size_spot; // Spot in the block where to store a copy of size
char *front_border; // The border bytes in front of the user's memory
char *middle; // The memory to be given to the calling program
char *back_border; // The border bytes at the back of the user's memory
sequence::size_type i; // Loop control variable

// Allocate the block of memory for the user and for the two borders.
whole_block = (char *) malloc(2*BORDER_SIZE + size);
if (whole_block == NULL)
{
cout << "Insufficient memory for a call to the new operator." << endl;
exit(0);
}

// Figure out the start points of the various pieces of the block.
size_spot = (sequence::size_type *) whole_block;
front_border = (char *) (whole_block + sizeof(sequence::size_type));
middle = (char *) (whole_block + BORDER_SIZE);
back_border = middle + size;

// Put a copy of the size at the start of the block.
*size_spot = size;

// Fill the borders and the middle section.
for (i = 0; i < BORDER_SIZE - sizeof(sequence::size_type); i++)
front_border[i] = BORDER;
for (i = 0; i < size; i++)
middle[i] = GARBAGE;
for (i = 0; i < BORDER_SIZE; i++)
back_border[i] = BORDER;

// Update the global static variable showing how much memory is now used.
memory_used_now += size;

return middle;
}


Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:


[ Follow Ups ] [ Post Followup ] [ CCNY CSc 212 Messages ] [ Help ]