Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #11678
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Ian Collins <ian-news@hotmail.com> |
| Newsgroups | comp.lang.c++ |
| Subject | Re: Memory Allocation Question |
| Date | Tue, 22 Nov 2011 19:18:19 +1300 |
| Lines | 56 |
| Message-ID | <9j0t5bFr4nU4@mid.individual.net> (permalink) |
| References | <ea77e8d4-e211-4a3e-ab6a-c254ea68fbf9@w7g2000yqc.googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | individual.net 1+1p/MfdbBrCPt6+x8LWfgUOcCceczjMgfMJERZO/YJGTiqjXQ |
| Cancel-Lock | sha1:/Lr3S3+Opghz4dhOy3LG5O8kO+A= |
| User-Agent | Mozilla/5.0 (X11; SunOS i86pc; rv:6.0.2) Gecko/20111003 Thunderbird/6.0.2 |
| In-Reply-To | <ea77e8d4-e211-4a3e-ab6a-c254ea68fbf9@w7g2000yqc.googlegroups.com> |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.c++:11678 |
Show key headers only | View raw
On 11/22/11 06:10 PM, Nephi Immortal wrote:
> I have a question about memory allocation. I discuss stack. You
> declare and define four char variables. One byte of char type
> allocates one byte into stack, but it actually allocates 16 bytes
> while leaving 15 bytes unused or wasted.
I very much doubt that, have you tried?
#include <iostream>
int main()
{
char a = '1';
char b = '3';
char c = '3';
char d = '4';
std::cout << std::hex << (void*)&a << ' '
<< (void*)&b << ' '
<< (void*)&c << ' '
<< (void*)&d << std::endl;
}
gives
fffffd7fffdffa07 fffffd7fffdffa06 fffffd7fffdffa05 fffffd7fffdffa04
on my box.
>
> I read several websites. They claim that heap allocates 32,768
> bytes, but only 1,000 bytes are used.
You should improve your reading list.
> char* e = new char[ 1000 ];
>
> Is it true that heap allocates 32K each variable? If not, how much
> total bytes do heap allocate each variable?
The answer depends on the implementation. Have you tried it?
char* p = new char[1000];
char* p1 = new char[1000];
std::cout << std::hex << (void*)p << ' ' << (void*)p1
<< ' ' << p1-p << std::endl;
gives
4374f0 4378f0 400
on my box.
--
Ian Collins
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Memory Allocation Question Nephi Immortal <immortalnephi@gmail.com> - 2011-11-21 21:10 -0800
Re: Memory Allocation Question Ian Collins <ian-news@hotmail.com> - 2011-11-22 19:18 +1300
Re: Memory Allocation Question Goran <goran.pusic@gmail.com> - 2011-11-21 23:25 -0800
Re: Memory Allocation Question Juha Nieminen <nospam@thanks.invalid> - 2011-11-22 07:59 +0000
csiph-web