helloworld

please help me, am confused in the memory bit, all i want is 32 k memory free and each time i add something and run it, it will say for example 27 k memory left

how to i make this program only have 32 k memory, for example At the beginning there will be no notthing running and none in the queue so the screen might show something like this:

32k free
none running:
-------------------------------------------------

Then 1 might enter the queue ( jobs start in the queue and then are chosen to execute ie they have to be in the queue first). The screen might look like this:

32k free
jobs running:

-------------------------------------------------

jobs in queue:

job 1 8 k p3

Suppose another job joins the queue:

32k free
jobs running:

-------------------------------------------------

jobs in queue:

job 1 8 k p3
job 2 4k p1

Then the operator decides to start job 2:

28k free
jobs running:

job 2 4k p1
-------------------------------------------------

jobs in queue:

job 1 8 k p3

Next job 1 is started:

20k free
jobs running:

job 2 4k p1
job 1 8 k p3
-------------------------------------------------
jobs in queue:

Then the operator halts job 2:

28k free
jobs running:

job 1 8 k p3

-------------------------------------------------

jobs in queue:

``````// Program to demonstrate a queue using nodePtrs
// The size of the queue is limited only by the
// amount of dynamic RAM available

#include <iostream.h>
#include <stdlib.h>

struct node;
typedef node *nodePtr;

struct node
{
char data;
nodePtr next;
};

struct queue
{
nodePtr front;
nodePtr rear;
};

void create(queue&);
bool empty(queue);
bool full();
void deleteFromQueue(queue&, char&);
void traverseQueue(queue);

void create(queue& Q)
{
Q.front = NULL;
Q.rear = NULL;
}

bool empty(queue Q)
{
if(Q.front == NULL)
return true;
else
return false;
}

bool full()
{
nodePtr temp =new node;

if (temp == NULL)
return true;
else
{
delete temp;
return false;
}
}

{
nodePtr temp;

temp = new node;
temp->data = item;
temp->next = NULL;

if (Q.front != NULL) // ie not empty
{
Q.rear->next = temp;
Q.rear = temp;
}
else
{
Q.front = temp;
Q.rear = temp;
}
}

void deleteFromQueue(queue& Q, char& item)
{
nodePtr temp;

if (Q.front != NULL)      // ie not empty
{
temp = Q.front;
item = temp->data;

if (Q.rear == Q.front) // ie single node so queue becomes empty
{
Q.front = NULL;
Q.rear = NULL;
}
else                  // more than one node
Q.front = temp->next;

delete temp;
}
}

void traverseQueue(queue Q)
{
nodePtr temp;

temp = Q.front;

while (temp != NULL)
{
cout << temp->data << endl;
temp =  temp->next;
}
}

void main()
{
queue q;
char command, letter;

create(q);
system("cls");

cout << "This program uses a queue implemented using pointers\n";
cout << "The number of items in the queue is only limited by\n";
cout << "amount of dynamic RAM available\n";

do
{
cout << "\n[A]dd to queue, [D]elete from queue, [P]rint queue, "  ;
cout << "or [Q]uit -> ";
cin >> command;
switch(command)
{
case 'a' :
case 'A' :  cout << "Enter data -> ";
cin >> letter;
break;
case 'd' :
case 'D' :  if (!empty(q))
{
deleteFromQueue(q, letter);
cout << letter << " removed from queue\n";
}
else
cout << "The queue is empty \n";
break;
case 'p' :
case 'P' :  traverseQueue(q);
break;
case 'q' :
case 'Q' : 	cout << "Program terminated\n";
break;
default  :	cout << "Unknown command [" << command << "] try again!\n";
}	// end switch
} while (!(command == 'q' || command == 'Q'));
}``````

helloworld

i need example, i need the code, as soon as possible

alc6379 120

i need example, i need the code, as soon as possible

That's nice. I need a new car, I need the vehicle, as soon as possible. Let's both sit here and wait to see who gets one first.

It's okay to post a question like this, as you've shown some effort, but it's still considered rude to insist that someone help you ASAP when others have been here before you, waiting patiently.

helloworld

the reason i need help is beccause i need to hand it in soon, that why

alc6379 120

the reason i need help is beccause i need to hand it in soon, that why

I know.

But, instead of posting it to a forum, get to coding. Someone here might be able to help you, but I'm focused on how your post seemed to convey a sense of urgency that we're not required to share here.

We're a free help forum. If we don't help you in time, you got what you paid for.

helloworld

do you know anything about c++. or have you just created this site for fun. i though you people knew certain things, i guess i was wrong. how hard can it be for creating a my program

1o0oBhP 4

how hard can it be for creating a my program

careful there! you couldnt do it either! What exactly is going wrong with it anyways? maybe we could give a hint if we know what is wrong?

Chainsaw 12

the standard C runtime routines to allocate and free memory do not have a way to tell you how much the OS has free. On Windows you can use GlobalMemoryStatus(), but that talks about total OS memory including all swap space and the like. If you are using another OS, you may have to poke around in the help files or docs for that OS.

But, even on Windows there may be process-level restrictions, and actions by other programs on the system can change the amount of free memory from moment to moment.

If you wanted to SIMULATE this for some theoretical smaller machine, you could write some code to break up a block of ram (maybe the 32k you keep referring to) into chunks rather than using 'new' and 'delete', and you could accurately report on the size of THAT block of ram.

as to "how hard can it be for creating a my program", we're here for help but not here to do your work for you. And we do this for free on our spare time. When we want to, for whom we want to. If you are not happy with the service, feel free to go elsewhere.

Narue 5,707

do you know anything about c++. or have you just created this site for fun. i though you people knew certain things, i guess i was wrong. how hard can it be for creating a my program

Bahahahahahahaha! That's a good one. "Here's my homework, do it for me because I don't believe that you can". Haha, thanks for the laugh retard, now go crawl back into your hole until you can understand why we won't be your code monkeys so that you can get a free ride in your class.