Re: [algogeeks] Re: deep vas shallow

2011-10-02 Thread rahul vatsa
ignore the prev mail, send button hd got clicked while i was typing .. :P


shallow copy
> -
>
> class MyString {
>
> char *str;
> public:
> MyString(char *);
> //MyString & operator=(const MyString & t);
> };
>
> MyString :: MyString(char *s)
> {



> int  len = strlen(s);
>
str = new char[len +1] ;
strcpy(str, s);

> }
>
> MyString a("rahul");
> MyString b;
>
> b = a;
>
> the default = operator does a bitwise copy, so if we don't overload the
> default behaviour, it will just copy the contents of a to b. so now both a &
> b will point to the same memory.
>
> this is shallow copy. nd it hs memory issues due to obvious reasons.
>
> deep copy
> ---
> a deep copy of a to b, should allocate memory for b nd den should copy the
> value of a to b.
> so, now both the objects have distinct memory allocated to it. So, ther
> wont be memory related issues here.
>
> to do deep copy, we need to overload the default behavior of the assignment
> operator.
>
> MyString & MyString :: operator=(const MyString & s);
> {
>int len = strlen(s);
>
  str = new char [len +1] ;
   strcpy(str, s);

> }
>
> now, wen  u do
> b= a
>
>
> now a & b will have memory allocated of their own.
>


>
> On Sun, Oct 2, 2011 at 2:21 AM, rahul sharma wrote:
>
>> means if i use like
>>
>> main()
>> {
>> int *ptr;
>> abc(ptr);
>> }
>> abc(int *a)
>> {
>> }
>> this is shallow copy
>> m i ryt???
>> if yes thne tell xample of deep shallow..otherwise give me examples
>> regarding c++cozxamples clear everythng
>>
>>
>> On Sun, Oct 2, 2011 at 11:00 AM, megha agrawal wrote:
>>
>>>  One function passes a pointer to the value of interest to another
>>> function. Both functions can access the
>>> value of interest, but the value of interest itself is not copied. This
>>> communication is
>>> called shallow. The alternative where a complete copy is made and sent is
>>> known as a "deep"
>>> copy.
>>>
>>> On Sat, Oct 1, 2011 at 7:36 PM, rahul sharma wrote:
>>>
 plz give any c++ xample to xplain bit more


 On Sat, Oct 1, 2011 at 6:59 PM, Bejoy kalikotay(sikkimesechora) <
 bijaykaliko...@gmail.com> wrote:

> A shallow copy of an object copies all of the member field values.
> This works well if the fields are values, but may not be what you want
> for fields that point to dynamically allocated memory. The pointer
> will be copied. but the memory it points to will not be copied -- the
> field in both the original object and the copy will then point to the
> same dynamically allocated memory, which is not usually what you want.
> The default copy constructor and assignment operator make shallow
> copies.
>
> A deep copy copies all fields, and makes copies of dynamically
> allocated memory pointed to by the fields. To make a deep copy, you
> must write a copy constructor and overload the assignment operator,
> otherwise the copy will point to the original, with disasterous
> consequences.
>
> On Oct 1, 4:50 pm, rahul sharma  wrote:
> > plz xpalin waht is deep and shallow copy in c++
>
> --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
  --
 You received this message because you are subscribed to the Google
 Groups "Algorithm Geeks" group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com

Re: [algogeeks] Re: deep vas shallow

2011-10-02 Thread rahul vatsa
shallow copy
-

class MyString {

char *str;
public:
MyString(char *);
//MyString & operator=(const MyString & t);
};

MyString :: MyString(char *)
{

}

MyString a("rahul");
MyString b;

b = a;

the default = operator does a bitwise copy, so if we don't overload the
default behaviour, it will just copy the contents of a to b. so now both a &
b will point to the same memory.

this is shallow copy. nd it hs memory issues due to obvious reasons.

deep copy
---
a deep copy of a to b, should allocate memory for b nd den should copy the
value of a to b.
so, now both the objects have distinct memory allocated to it. So, ther wont
be memory related issues here.

to do deep copy, we need to overload the default behavior of the assignment
operator.

MyInt & MyInt :: operator=(const MyInt & t);
{

}

now, wen  u do
b= a


instead of memory  there may be any resource which 2 objects shouldn't
share.


On Sun, Oct 2, 2011 at 2:21 AM, rahul sharma wrote:

> means if i use like
>
> main()
> {
> int *ptr;
> abc(ptr);
> }
> abc(int *a)
> {
> }
> this is shallow copy
> m i ryt???
> if yes thne tell xample of deep shallow..otherwise give me examples
> regarding c++cozxamples clear everythng
>
>
> On Sun, Oct 2, 2011 at 11:00 AM, megha agrawal wrote:
>
>>  One function passes a pointer to the value of interest to another
>> function. Both functions can access the
>> value of interest, but the value of interest itself is not copied. This
>> communication is
>> called shallow. The alternative where a complete copy is made and sent is
>> known as a "deep"
>> copy.
>>
>> On Sat, Oct 1, 2011 at 7:36 PM, rahul sharma wrote:
>>
>>> plz give any c++ xample to xplain bit more
>>>
>>>
>>> On Sat, Oct 1, 2011 at 6:59 PM, Bejoy kalikotay(sikkimesechora) <
>>> bijaykaliko...@gmail.com> wrote:
>>>
 A shallow copy of an object copies all of the member field values.
 This works well if the fields are values, but may not be what you want
 for fields that point to dynamically allocated memory. The pointer
 will be copied. but the memory it points to will not be copied -- the
 field in both the original object and the copy will then point to the
 same dynamically allocated memory, which is not usually what you want.
 The default copy constructor and assignment operator make shallow
 copies.

 A deep copy copies all fields, and makes copies of dynamically
 allocated memory pointed to by the fields. To make a deep copy, you
 must write a copy constructor and overload the assignment operator,
 otherwise the copy will point to the original, with disasterous
 consequences.

 On Oct 1, 4:50 pm, rahul sharma  wrote:
 > plz xpalin waht is deep and shallow copy in c++

 --
 You received this message because you are subscribed to the Google
 Groups "Algorithm Geeks" group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: deep vas shallow

2011-10-01 Thread rahul sharma
means if i use like

main()
{
int *ptr;
abc(ptr);
}
abc(int *a)
{
}
this is shallow copy
m i ryt???
if yes thne tell xample of deep shallow..otherwise give me examples
regarding c++cozxamples clear everythng


On Sun, Oct 2, 2011 at 11:00 AM, megha agrawal wrote:

>  One function passes a pointer to the value of interest to another
> function. Both functions can access the
> value of interest, but the value of interest itself is not copied. This
> communication is
> called shallow. The alternative where a complete copy is made and sent is
> known as a "deep"
> copy.
>
> On Sat, Oct 1, 2011 at 7:36 PM, rahul sharma wrote:
>
>> plz give any c++ xample to xplain bit more
>>
>>
>> On Sat, Oct 1, 2011 at 6:59 PM, Bejoy kalikotay(sikkimesechora) <
>> bijaykaliko...@gmail.com> wrote:
>>
>>> A shallow copy of an object copies all of the member field values.
>>> This works well if the fields are values, but may not be what you want
>>> for fields that point to dynamically allocated memory. The pointer
>>> will be copied. but the memory it points to will not be copied -- the
>>> field in both the original object and the copy will then point to the
>>> same dynamically allocated memory, which is not usually what you want.
>>> The default copy constructor and assignment operator make shallow
>>> copies.
>>>
>>> A deep copy copies all fields, and makes copies of dynamically
>>> allocated memory pointed to by the fields. To make a deep copy, you
>>> must write a copy constructor and overload the assignment operator,
>>> otherwise the copy will point to the original, with disasterous
>>> consequences.
>>>
>>> On Oct 1, 4:50 pm, rahul sharma  wrote:
>>> > plz xpalin waht is deep and shallow copy in c++
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: deep vas shallow

2011-10-01 Thread megha agrawal
 One function passes a pointer to the value of interest to another function.
Both functions can access the
value of interest, but the value of interest itself is not copied. This
communication is
called shallow. The alternative where a complete copy is made and sent is
known as a "deep"
copy.

On Sat, Oct 1, 2011 at 7:36 PM, rahul sharma wrote:

> plz give any c++ xample to xplain bit more
>
>
> On Sat, Oct 1, 2011 at 6:59 PM, Bejoy kalikotay(sikkimesechora) <
> bijaykaliko...@gmail.com> wrote:
>
>> A shallow copy of an object copies all of the member field values.
>> This works well if the fields are values, but may not be what you want
>> for fields that point to dynamically allocated memory. The pointer
>> will be copied. but the memory it points to will not be copied -- the
>> field in both the original object and the copy will then point to the
>> same dynamically allocated memory, which is not usually what you want.
>> The default copy constructor and assignment operator make shallow
>> copies.
>>
>> A deep copy copies all fields, and makes copies of dynamically
>> allocated memory pointed to by the fields. To make a deep copy, you
>> must write a copy constructor and overload the assignment operator,
>> otherwise the copy will point to the original, with disasterous
>> consequences.
>>
>> On Oct 1, 4:50 pm, rahul sharma  wrote:
>> > plz xpalin waht is deep and shallow copy in c++
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: deep vas shallow

2011-10-01 Thread rahul sharma
plz give any c++ xample to xplain bit more

On Sat, Oct 1, 2011 at 6:59 PM, Bejoy kalikotay(sikkimesechora) <
bijaykaliko...@gmail.com> wrote:

> A shallow copy of an object copies all of the member field values.
> This works well if the fields are values, but may not be what you want
> for fields that point to dynamically allocated memory. The pointer
> will be copied. but the memory it points to will not be copied -- the
> field in both the original object and the copy will then point to the
> same dynamically allocated memory, which is not usually what you want.
> The default copy constructor and assignment operator make shallow
> copies.
>
> A deep copy copies all fields, and makes copies of dynamically
> allocated memory pointed to by the fields. To make a deep copy, you
> must write a copy constructor and overload the assignment operator,
> otherwise the copy will point to the original, with disasterous
> consequences.
>
> On Oct 1, 4:50 pm, rahul sharma  wrote:
> > plz xpalin waht is deep and shallow copy in c++
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.