size_t

Jan 6, 2011 at 11:02am
Class A{
int p [100];
};

What is size_t A?

Is this true that every type actually has a constant "size"
Jan 6, 2011 at 2:26pm
size_t is a type itself (e.g. sizeof resolves to this).

Is this true that every type actually has a constant "size"
Yes
Jan 7, 2011 at 10:13am
So size_t A will be pretty small. A has like a pointer, and that's it. right?
Jan 7, 2011 at 10:14am
Where do p[100] is located then when we do


A someA=new A();

Heap?
Jan 7, 2011 at 10:49am
So size_t A will be pretty small. A has like a pointer, and that's it. right?
if you write size_t A then 'A' has nothing to do with the aforementioned class. 'A' has the type size_t (usually unsigned long). No pointer at all.

Where do p[100] is located then when we do


A someA=new A();

Heap?
'p' is part of 'class A' so yes: heap.
Jan 7, 2011 at 12:25pm
Where do p[100] is located then when we do


A someA=new A();

Heap?

Jan 10, 2011 at 4:00am
Ah wrong question.

Where do P[100] is located when we do.

A someA;

I forget that in C++ new returns a pointer. He he he he.... That means my previous code is invalid.
Jan 10, 2011 at 4:01am
Also what would be sizeof (A)? It should be pretty small isn't it because p is just a pointer.
Jan 10, 2011 at 4:39am
I was under the impression that p would be allocated where-ever A was allocated?

So,
1
2
A someA1; // someA1 and associated p are allocated onto the stack
A *someA2 = new A(); // someA1 and associated p are allocated onto the heap 


However, if A was defined to create p using new, then p would always be put on the heap.

1
2
3
4
5
6
7
8
9
10
11
Class A{
int p*;
public A(void)
{
    p = new int[100];
}
public ~A(void)
{
    delete[] p;
}
};


If I'm wrong, someone please correct me :P
Jan 11, 2011 at 11:03am
teguh123 wrote:
Where do P[100] is located when we do.

A someA;
stack. All members of a class/struct will be located where the enveloping class/struct is located.

helloworld922 is right

teguh123 wrote:
Also what would be sizeof (A)? It should be pretty small isn't it because p is just a pointer.
p is not a pointer (can be used as such) in your case it's an array of int. So sizeof(A) will be 100 * sizeof(int) + may be some overhead.
Topic archived. No new replies allowed.