i need some help,
is there a program which will only have let say 40k of memory, for example a program that will use queues, when you enter a number it will say you have use 10 k memory , please someone help so me a example, please
i need some help,
is there a program which will only have let say 40k of memory, for example a program that will use queues, when you enter a number it will say you have use 10 k memory , please someone help so me a example, please
can you post what you've coded so far please?
>when you enter a number it will say you have use 10 k memory
That's one hell of a number.
>please someone help so me a example, please
Please ask a coherent question instead of whatever it was you said in broken english.
I belive he is trying to allocate a certain % of his memory to this program, everytime the user uses this proram to store data it will use a % of allocated memory. I belive that "helloworld" is wanting to calculate the amount that is in use and return the amount left for the user to see.
However based on the lack of information provided i can only see this has a logical conclusion - but struggle to see why you would want such program
>I belive that "helloworld" is wanting to calculate the amount that is in use and return the amount left for the user to see.
Well, it doesn't really matter what you believe does it? It would be a waste of effort to answer an incomplete question because the answer would likely be incomplete as a result. That accomplishes nothing.
>I belive that "helloworld" is wanting to calculate the amount that is in use and return the amount left for the user to see.
Well, it doesn't really matter what you believe does it? It would be a waste of effort to answer an incomplete question because the answer would likely be incomplete as a result. That accomplishes nothing.
hi
how can say me about c++.net
i think memory management is very important
if i did any code, do you really think i would need your help, as you know 1kb is 1024 byes, therefore 40 kb is 40960 byes, how can i write a program which only has 40 kb.
Do you people practice being incomprehensible?
>if i did any code, do you really think i would need your help
Okay then, I won't try to help you if you don't need it.
I wonder what happened to english lessons :) if you want to write a program which is in total only 40KB then I would turn to assembly language and assemblers as c++ tends to bind rather bulky static libs to its *.exe files. Other than that PLEASE give some details helloworld - which SOMEONE ELSE can follow - if you need some help with something!!!! :)
ok is need to be done using queues, for example the first thing that should come up is 40k memory free, then for example if you wanted to add two number the program would go in the queue, and say you have 35 k memory left, i just need a example , any exapmle pref with c++ codes, i belive you will need to use arrays
Still not enough detail, but at least now it sounds like you want to maintain a count of the memory available starting with 40k. The only good way to track memory usage from an arbitrary upper limit is to restrict how memory is gathered by the application. This almost always results in some type of garbage collection, often in the form of a checked arena:
#include <iostream>
#include <stdexcept>
#include <vector>
using namespace std;
class Arena {
public:
Arena(int avail): remaining(avail) {}
~Arena();
public:
template <typename T> void *alloc();
void avail() const { cout<< remaining <<" bytes available"<<endl; }
private:
vector<void *> arena;
int remaining;
};
Arena::~Arena()
{
vector<void *>::iterator it = arena.begin();
while (it != arena.end())
delete *it++;
}
template <typename T>
void *Arena::alloc()
{
if (sizeof(T) > remaining)
throw runtime_error("Not enough memory");
arena.push_back(new T);
remaining -= sizeof(T);
return arena.back();
}
int main()
{
Arena a(40960);
int *p;
p = static_cast<int *>(a.alloc<int>()); a.avail();
*p = 12345;
cout<<"*p == "<< *p <<endl;
// Trash the arena
try {
while (1) {
a.alloc<double>(); a.avail();
}
}
catch (runtime_error& err) {
cerr<< err.what() <<endl;
}
}
I think thats what he is asking! Helloworld i believe there are many memory management tutorials on the internet. Google searching would get results fast. Another way might be to use the 'new' and 'delete' operator to declare an array of a given size (so there your program uses arrays and has a certain memory available?). This could be what you need - as most people ask about the 'new' and 'delete' with reference to re-dimensioning arrays, or in this case, re-defining how much memory you want to track...
ie something like:
typdef unsigned char byte;
byte *my_40k_array = (byte*)new byte[40960]; // make it
delete [] my_40k_array; // delete it at program end
When you say using queues is this a computer science question? i dont understand what you mean by a queue, perhaps explaining that or some sort of example output will clear things up! if not there is a comp science forum here also
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.