•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 391,734 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,235 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 1738 | Replies: 8
![]() |
•
•
Join Date: Dec 2004
Posts: 21
Reputation:
Rep Power: 0
Solved Threads: 0
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:
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 addToQueue(queue&, char);
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;
}
}
void addToQueue(queue& Q, char item)
{
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;
addToQueue(q, 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'));
} Last edited by alc6379 : Jan 5th, 2005 at 4:38 pm.
•
•
Join Date: Dec 2003
Location: Nashville, TN
Posts: 2,333
Reputation:
Rep Power: 11
Solved Threads: 101
•
•
•
•
Originally Posted by helloworld
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.
Alex Cavnar, aka alc6379
•
•
Join Date: Dec 2003
Location: Nashville, TN
Posts: 2,333
Reputation:
Rep Power: 11
Solved Threads: 101
•
•
•
•
Originally Posted by helloworld
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.
Alex Cavnar, aka alc6379
•
•
Join Date: Jun 2004
Location: Marin, CA, USA
Posts: 434
Reputation:
Rep Power: 5
Solved Threads: 10
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.
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.
•
•
•
•
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
Member of: Beautiful Code Club.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
- memory (C++)
Other Threads in the C++ Forum
- Previous Thread: This may be a stupid question....
- Next Thread: help



Linear Mode