>
> ------------------------------
>
> Message: 4
> Date: Wed, 3 Aug 2011 16:25:13 +0200
> From: Stephan Beal <[email protected]>
> Subject: Re: [sqlite] Deep copy of 2 sqlite3*?
> To: General Discussion of SQLite Database <[email protected]>
> Message-ID:
>        <CAKd4nAj==+ga_dhfok6b8rpygfzqubkxqpsy3q37gtaz_7l...@mail.gmail.com
> >
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Wed, Aug 3, 2011 at 12:56 PM, Teg <[email protected]> wrote:
>
> > I'd suggest either not doing it (prevent the copy constructor from
> > compiling by declaring it private) or doing it by passing ownership of
> > the connection around as if it was a socket or file handle.
> >
>
> +1 to that.
>
> It is "almost never" a good idea to implement copy ctors for classes which
> refer to stream handles and such.
>
> The absolute simplest/sanest/safest way to implement this is to declare the
> copy ctor and copy assignment operator as private and NOT implement them.
>
> --
> ----- stephan beal
> http://wanderinghorse.net/home/stephan/
>
>
> ------------------------------
>
>
> ------------------------------
>
> Message: 6
> Date: Wed, 3 Aug 2011 17:17:24 +0200
> From: Stephan Beal <[email protected]>
> Subject: Re: [sqlite] Deep copy of 2 sqlite3*?
> To: General Discussion of SQLite Database <[email protected]>
> Message-ID:
>        <CAKd4nAifdjN_S651O4RkzNJXzyKr=sPvD9KiBK0k=dFZED=o...@mail.gmail.com
> >
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Wed, Aug 3, 2011 at 4:20 AM, Nikki Tan <[email protected]> wrote:
>
> > Hi sqlite-users!
> >    It's just that I'm writing a copy constructor of my own mini sqlite
> > wrapper, and I ended up having to do a deep copy of a sqlite3* points to
> a
> > SQLite connection. And I'm just wondering is it okay that I just do it
> with
> > memcpy(), by digging into the code for the definition of struct sqlite3
> >  and
> > count the total bytes of this struct?
> >
>
>
> Another point: memcpy() will NOT do what you want here because the sqlite3
> structure dynamically allocates OTHER structures and points to them. A
> memcpy() will copy the pointers but not their contents. i.e. you'll have 2
> copies of an sqlite3 handle which both point to (and own!) the underying
> memory.
>
> NEVER use memcpy() to copy non-trivial types (e.g. those which contain
> owned
> pointers).
>
> --
> ----- stephan beal
> http://wanderinghorse.net/home/stephan/
>
>
>    Yes and indeed to "Another point:", thanks for all the suggestions!!
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to