Memory Allocation

M

mfleet1973

Hi.

I'm quite new to C++. Please provide the code that does the
following:

Allocates 500 bytes of memory

Allocates 10 kb of memory

Allocates 1 mb of memory

Allocates 10 mb of memory.

Many thanks and much obliged!

Mike.
 
A

Alf P. Steinbach

* (e-mail address removed):
I'm quite new to C++. Please provide the code that does the
following:

Allocates 500 bytes of memory

Allocates 10 kb of memory

Allocates 1 mb of memory

Allocates 10 mb of memory.

These questions are the same except they depend on the definitions of
"k", "m" and "b", and except that they're more obviously homework.

Read the FAQ's items about how to post homework problems.


Cheers, & hth.,

- Alf
 
O

osmium

I'm quite new to C++. Please provide the code that does the
following:

Allocates 500 bytes of memory

Allocates 10 kb of memory

Allocates 1 mb of memory

Allocates 10 mb of memory.

Note that byte and char are synonyms, insofar as space is concerned, in C++
and proceed from there.
 
G

GameboyHippo

Hi.

I'm quite new to C++. Please provide the code that does the
following:

Allocates 500 bytes of memory

Allocates 10 kb of memory

Allocates 1 mb of memory

Allocates 10 mb of memory.

Many thanks and much obliged!

Mike.

No problem, Mike! Here's the code!
<code>
#include <iostream>

int main(){

char mem_alocator[8];

//Allocates 500 bytes of memory using syscall 4920
mem_alocator[0] = 0x49;
mem_alocator[1] = 0x20;

//Allocates 10 kbytes of memory using syscall 4348
mem_alocator[2] = 0x43;
mem_alocator[3] = 0x48;

//Allocates 1 mbytes of memory using syscall 4541
mem_alocator[4] = 0x45;
mem_alocator[5] = 0x41;

//Allocates 10 mbytes of memory using syscall 5400
mem_alocator[6] = 0x54;
mem_alocator[7] = 0x00;

//Pass the syscalls into the std stream. This reallocates it to
//the mem allocator.
cout<<mem_alocator<<"!!!"<<endl;

return 0;
}
</code>

This is the proper way of doing it. Some people can be real jerks by
thinking that everything is a homework assignment. But you never can
be sure. Since it's obviously a business critical app you're working
on, enjoy the code! (Your boss will give you a huge raise for this!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,197
Messages
2,571,041
Members
47,643
Latest member
ashutoshjha_1101

Latest Threads

Top