www.digitalmars.com         C & C++   DMDScript  

c++.stlsoft - [STLSoft] Windows Clipboard Library: class clipboard_scope: issue

reply Martin Moene <moene eld.physics.LeidenUniv.nl> writes:
[STLSoft] Windows Clipboard Library: class clipboard_scope: issue with 
deallocating string memory
___

Hi Matthew,

I'm trying the small example program for the clipboard_scope class from 
STLSoft's Windows Clipboard Library. See below.

I encounter the following issues :

1. scope.get_allocator().deallocate( cstr );    // as in doc: old name

2. scope.get_allocator().do_deallocate( cstr ); // do_deallocate: private!

3. shouldn't class clipboard_scope besides scoping the clipboard handle
    also take care of deallocating the memory allocated for the string
    returnd by  scope.get_data( cstr ); ?  (I don't think it does.)

Just to inform you, I'm not depending on it.

Cheers,

Martin.
___

#include <winstl/clipboard/clipboard_scope.hpp>

#include <algorithm>    // std::copy
#include <iostream>     // std::cout, std::endl

int main()
{
    try
    {
       // set the data on the clipboard:
       {
          winstl::clipboard_scope  scope;

          scope.set_data( "Text from clipboard_scope demo." );
       }

       /*
        * as long as no other thread/process changes the clipboard contents
        * in the meanwhile, this can then be read back, as follows:
        */
       {
          winstl::clipboard_scope   scope;
          char const                *cstr;

          scope.get_data( cstr );

          std::cout << "Clipboard data: " << cstr << std::endl;

//         scope.get_allocator().do_deallocate( cstr ); // private!
       }
    }
    catch( std::exception const& e )
    {
       std::cerr << "Exception: " << e.what() << std::endl;
    }
}

// cl -W3 -EHsc -I%STLSOFT%/include winstl_clipboard_scope.cpp user32.lib
Jun 11 2008
next sibling parent "Matthew Wilson" <matthew hat.stlsoft.dot.org> writes:
Am answering in a rush here, but deallocation is only required when pushing
onto the clipboard fails. When it succeeds, the memory
is then owned by the operating system, which will release it at the appropriate
time. This is why it uses the global allocator.

If I had written any design documents, this'd be apparent. :$

btw, am very grateful for your continuing interest and efforts on STLSoft, and
I hope in a few weeks' time to get time to be able to
lend a hand. ;-)

"Martin Moene" <moene eld.physics.LeidenUniv.nl> wrote in message
news:48501AC7.3000200 eld.physics.LeidenUniv.nl...
 [STLSoft] Windows Clipboard Library: class clipboard_scope: issue with
 deallocating string memory
 ___

 Hi Matthew,

 I'm trying the small example program for the clipboard_scope class from
 STLSoft's Windows Clipboard Library. See below.

 I encounter the following issues :

 1. scope.get_allocator().deallocate( cstr );    // as in doc: old name

 2. scope.get_allocator().do_deallocate( cstr ); // do_deallocate: private!

 3. shouldn't class clipboard_scope besides scoping the clipboard handle
     also take care of deallocating the memory allocated for the string
     returnd by  scope.get_data( cstr ); ?  (I don't think it does.)

 Just to inform you, I'm not depending on it.

 Cheers,

 Martin.
 ___

 #include <winstl/clipboard/clipboard_scope.hpp>

 #include <algorithm>    // std::copy
 #include <iostream>     // std::cout, std::endl

 int main()
 {
     try
     {
        // set the data on the clipboard:
        {
           winstl::clipboard_scope  scope;

           scope.set_data( "Text from clipboard_scope demo." );
        }

        /*
         * as long as no other thread/process changes the clipboard contents
         * in the meanwhile, this can then be read back, as follows:
         */
        {
           winstl::clipboard_scope   scope;
           char const                *cstr;

           scope.get_data( cstr );

           std::cout << "Clipboard data: " << cstr << std::endl;

 //         scope.get_allocator().do_deallocate( cstr ); // private!
        }
     }
     catch( std::exception const& e )
     {
        std::cerr << "Exception: " << e.what() << std::endl;
     }
 }

 // cl -W3 -EHsc -I%STLSOFT%/include winstl_clipboard_scope.cpp user32.lib

Jun 11 2008
prev sibling parent Matt Wilson <matthewwilson acm.org> writes:
Hi Martin

I've added comments to the get_data() overloads in
winstl/clipboard/clipboard_scope.hpp that clarify the resource ownership
semantics, and also removed the erroneous line from the class documentation
markup

It'll be included in the next release

Thanks

Matt

Martin Moene Wrote:

 [STLSoft] Windows Clipboard Library: class clipboard_scope: issue with 
 deallocating string memory
 ___
 
 Hi Matthew,
 
 I'm trying the small example program for the clipboard_scope class from 
 STLSoft's Windows Clipboard Library. See below.
 
 I encounter the following issues :
 
 1. scope.get_allocator().deallocate( cstr );    // as in doc: old name
 
 2. scope.get_allocator().do_deallocate( cstr ); // do_deallocate: private!
 
 3. shouldn't class clipboard_scope besides scoping the clipboard handle
     also take care of deallocating the memory allocated for the string
     returnd by  scope.get_data( cstr ); ?  (I don't think it does.)
 
 Just to inform you, I'm not depending on it.
 
 Cheers,
 
 Martin.
 ___
 
 #include <winstl/clipboard/clipboard_scope.hpp>
 
 #include <algorithm>    // std::copy
 #include <iostream>     // std::cout, std::endl
 
 int main()
 {
     try
     {
        // set the data on the clipboard:
        {
           winstl::clipboard_scope  scope;
 
           scope.set_data( "Text from clipboard_scope demo." );
        }
 
        /*
         * as long as no other thread/process changes the clipboard contents
         * in the meanwhile, this can then be read back, as follows:
         */
        {
           winstl::clipboard_scope   scope;
           char const                *cstr;
 
           scope.get_data( cstr );
 
           std::cout << "Clipboard data: " << cstr << std::endl;
 
 //         scope.get_allocator().do_deallocate( cstr ); // private!
        }
     }
     catch( std::exception const& e )
     {
        std::cerr << "Exception: " << e.what() << std::endl;
     }
 }
 
 // cl -W3 -EHsc -I%STLSOFT%/include winstl_clipboard_scope.cpp user32.lib

Aug 12 2008