Hi friends,

This may a childish question but please help me out.
I want to know whether there is any dfference between Heap and free Store in C++ (dynamic memory) or they are the same i.e just the synonyms used?

One more thing i want to know is that where can i get the "C++ standard docs"?

One more thing I want to know is that where do, const variables (i.e constants or literals get memory) , is there is separate area for them or they are allocated in the data region only.

Reply at your earliest convenience.
Thanks,
himanshu k.
SymbianC++ Application Developer.

Recommended Answers

All 2 Replies

> I want to know whether there is any dfference between Heap and free Store in C++
Same thing, different terminology.

> where can i get the "C++ standard docs"?
The "official" document can be found at the ISO, NCTIS, or ANSI websites. IT costs money though, $30 to be exact. Worth every penny. :) Wiley published the 1998 standard in book form for $60, but you can probably find it used on Amazon for less than that. You can also search Google for the draft standard, and that's free.

> where do, const variables (i.e constants or literals get memory)
It depends on your compiler. Literals are probably going to really be literal in that they're hard coded right into the machine code. They'd be stored along with the rest of the code. Const variables usually have to have an address so you can pretend that they're stored with variables of the same scope. It really doesn't matter where the memory is stored though, you shouldn't need to care, thankfully. ;)

> dfference between Heap and free Store in C++
http://www.devx.com/tips/Tip/13757
http://www.research.att.com/~bs/bs_faq2.html#realloc

> const variables (i.e constants or literals get memory) , is there is separate area for them
> or they are allocated in the data region only.
they may not be allocated at all. as per the standard,

A pointer or reference to a cv-qualified type need not actually point
or refer to a cv-qualified object, but it is treated as if it does; ...

Except that any class member declared mutable can be modified,
any attempt to modify a const object during its lifetime
results in undefined behavior.

a good compiler can optimize them away. eg.

int fun( int a )
{
  static const int b = 7 ;
  const int c = 3 ;
  const int* pb = &b ;
  const int* pc = &c ;
  return a + *pb + *pc ;
}

>c++ -O3 -S -fomit-frame-pointer -c consts.cc

.file	"consts.cc"
	.text
	.align 2
	.p2align 4,,15
.globl _Z3funi
	.type	_Z3funi, @function
_Z3funi:
.LFB2:
	movl	4(%esp), %eax
	addl	$10, %eax
	ret
.LFE2:
	.size	_Z3funi, .-_Z3funi
.globl __gxx_personality_v0
	.ident	"GCC: (GNU) 4.2.1 20070719  [FreeBSD]"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.