Re: [osg-users] Deleting osg::Image that is shallow copied

2016-08-16 Thread Pierre-Jean Petitprez

Hi Robert and Christian,

Thank you for your answers.  Now I understand why my expectations on 
using the shallow copy were not working.

So I will just share the same osg::Image.
Also thanks for pointing out the allocation mode, it can be very useful 
if I want to manually manage the _data pointer.


Thanks for your help,

Cheers
Pierre-Jean

Le 16/08/2016 à 13:21, Robert Osfield a écrit :

Hi Pierre-Jean,

The osg::Image constructor doesn't support shallow copy for the
internal image data, it will allocated a new image block and copy
across the data.  This means for the image data itself it's effective
a deep copy.

A shallow copy would be technically possible by would force one to
start reference counting the image data.  However, this doesn't make
any sense in the context of an osg::Image, if you want to share the
image data then you should be sharing the osg::Image object not the
internal data it holds.

My recommendation is not to do a shallow copy at all, but just share
the osg::Image.


Robert.

On 16 August 2016 at 10:27, Pierre-Jean Petitprez
 wrote:

Hi,

In my application I have two osg::Images, the second one is a shallow copy of 
the first one thanks to the copy constructor.
Is it safe to delete the first image and keep only the second one, or should I 
use deep copy instead?
My tests showed me that the data is still reachable but when looking at the 
image destructor it clearly deallocates the data.

Thanks for enlightening me,

Cheers,
Pierre-Jean

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=68380#68380





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Deleting osg::Image that is shallow copied

2016-08-16 Thread Robert Osfield
Hi Pierre-Jean,

The osg::Image constructor doesn't support shallow copy for the
internal image data, it will allocated a new image block and copy
across the data.  This means for the image data itself it's effective
a deep copy.

A shallow copy would be technically possible by would force one to
start reference counting the image data.  However, this doesn't make
any sense in the context of an osg::Image, if you want to share the
image data then you should be sharing the osg::Image object not the
internal data it holds.

My recommendation is not to do a shallow copy at all, but just share
the osg::Image.


Robert.

On 16 August 2016 at 10:27, Pierre-Jean Petitprez
 wrote:
> Hi,
>
> In my application I have two osg::Images, the second one is a shallow copy of 
> the first one thanks to the copy constructor.
> Is it safe to delete the first image and keep only the second one, or should 
> I use deep copy instead?
> My tests showed me that the data is still reachable but when looking at the 
> image destructor it clearly deallocates the data.
>
> Thanks for enlightening me,
>
> Cheers,
> Pierre-Jean
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=68380#68380
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Deleting osg::Image that is shallow copied

2016-08-16 Thread Christian Buchner
looking at the osg::Image header file, it appears that the data storage is
not protected through reference counting.

AllocationMode _allocationMode;
unsigned char* _data;

the default allocation mode for an osg::Image is USE_NEW_DELETE, hence when
one instance of your shallow copy is destroyed, it will delete[] the _data
storage, making it unsafe to use from the 2nd instance.

You could force an allocation mode of NO_DELETE, so the osg::Image object
itself will never free its associated image data store - then your
application is responsible for freeing up these resources.

Christian



2016-08-16 12:35 GMT+02:00 Pierre-Jean Petitprez <
pierre-jean.petitp...@inria.fr>:

> Hi Sebastian,
>
> What do you mean by "reachable"? Deallocation doesn't mean the memory is
>> cleaned or something. So having a raw pointer to the deallocated memory
>> might give you the same data as long as no one is allocating memory there.
>>
>> I mean that after the first image is deleted, I still can use and perform
> operations on the data through the second image. To rewrite my question, I
> would like to know if data in an image is deallocated (and so it is not
> safe to perform operations on it through the second image) when it's
> shallow copied. I guess it is but I am not 100% sure.
>
> Thank you,
>
> Pierre-Jean
>
> Cheers
>> Sebastian
>>
>>>
>>> Thanks for enlightening me,
>>>
>>> Cheers,
>>> Pierre-Jean
>>>
>>> --
>>> Read this topic online here:
>>> http://forum.openscenegraph.org/viewtopic.php?p=68380#68380
>>>
>>>
>>>
>>>
>>>
>>> ___
>>> osg-users mailing list
>>> osg-users@lists.openscenegraph.org
>>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-opens
>>> cenegraph.org
>>>
>>
>>
>> ___
>> osg-users mailing list
>> osg-users@lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Deleting osg::Image that is shallow copied

2016-08-16 Thread Pierre-Jean Petitprez

Hi Sebastian,

What do you mean by "reachable"? Deallocation doesn't mean the memory 
is cleaned or something. So having a raw pointer to the deallocated 
memory might give you the same data as long as no one is allocating 
memory there.


I mean that after the first image is deleted, I still can use and 
perform operations on the data through the second image. To rewrite my 
question, I would like to know if data in an image is deallocated (and 
so it is not safe to perform operations on it through the second image) 
when it's shallow copied. I guess it is but I am not 100% sure.


Thank you,

Pierre-Jean

Cheers
Sebastian


Thanks for enlightening me,

Cheers,
Pierre-Jean

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=68380#68380





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org 




___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Deleting osg::Image that is shallow copied

2016-08-16 Thread Sebastian Messerschmidt

Hi Pierre

Hi,

In my application I have two osg::Images, the second one is a shallow copy of 
the first one thanks to the copy constructor.
Is it safe to delete the first image and keep only the second one, or should I 
use deep copy instead?
My tests showed me that the data is still reachable but when looking at the 
image destructor it clearly deallocates the data.
What do you mean by "reachable"? Deallocation doesn't mean the memory is 
cleaned or something. So having a raw pointer to the deallocated memory 
might give you the same data as long as no one is allocating memory there.


Cheers
Sebastian


Thanks for enlightening me,

Cheers,
Pierre-Jean

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=68380#68380





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Deleting osg::Image that is shallow copied

2016-08-16 Thread Pierre-Jean Petitprez
Hi,

In my application I have two osg::Images, the second one is a shallow copy of 
the first one thanks to the copy constructor.
Is it safe to delete the first image and keep only the second one, or should I 
use deep copy instead? 
My tests showed me that the data is still reachable but when looking at the 
image destructor it clearly deallocates the data.

Thanks for enlightening me,

Cheers,
Pierre-Jean

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=68380#68380





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org