Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > will memory be reserved for this object?

Reply
Thread Tools

will memory be reserved for this object?

 
 
Good Guy
Guest
Posts: n/a
 
      10-20-2010
I have following two classes:

template <size_t size>
class Cont{
public:
char charArray[size];
};
template <size_t size>
class ArrayToUse{
public:
Cont<size> container;
inline ArrayToUse(const Cont<size+1> &
input):container(reinterpret_cast<const Cont<size> &>(input)){}
};

I have two following lines of code at global scope:

const Cont<12> container={"hello world"};
ArrayToUse<11> temp(container);
char (&charArray)[11]=temp.container.charArray;

In totality of my code The only usage of "container" object is for
initialization of an object of "ArrayToUse" class as mentioned and
after initialization of "charArray" reference to
"temp.container.charArray" I'll use that reference in rest of my code,
now I'm wondering whether after building the code memory will be
reserved for "container" object or not since that's got a temporary
usage.
 
Reply With Quote
 
 
 
 
Helge Kruse
Guest
Posts: n/a
 
      10-20-2010

"Good Guy" <> wrote in message
news:d7116df9-7ffc-44fe-992f-...
>
> I have two following lines of code at global scope:
>
> const Cont<12> container={"hello world"};
> ArrayToUse<11> temp(container);
> char (&charArray)[11]=temp.container.charArray;
>
> In totality of my code The only usage of "container" object is for
> initialization of an object of "ArrayToUse" class as mentioned and
> after initialization of "charArray" reference to
> "temp.container.charArray" I'll use that reference in rest of my code,
> now I'm wondering whether after building the code memory will be
> reserved for "container" object or not since that's got a temporary
> usage.


Since it's a global object, the object's life time is not limited.

You can define in any other compilation unit "extern const Cont<12>
container;" and reference this object. The compiler cannot know this while
compiling the compilation unit where you define container, temp and
charArray.

Helge


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Are Python's reserved words reserved in places they dont need to be? metaperl Python 32 09-15-2006 02:02 PM
RE: Are Python's reserved words reserved in places they dont needtobe? Delaney, Timothy (Tim) Python 10 09-14-2006 04:17 PM
Re: Are Python's reserved words reserved in places they dont needtobe? Steve Holden Python 0 09-13-2006 08:44 AM
Unable to consume Process reserved memory Aravind C++ 2 08-06-2005 05:42 AM
Amount of heap memory reserved by a procces jose luis fernandez diaz C++ 2 02-09-2004 10:10 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57