• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Using STL collections in Photoshop plug-ins

New Here ,
Nov 02, 2007 Nov 02, 2007

Copy link to clipboard

Copied

Hello!<br /><br />Would you explain one moment. I need use a lot of STL collections in my Photoshop plug-in.<br /><br />First, I try to write something like<br />---------------------------------------------------------------------<br />#include <map><br />#include <string><br /><br />...<br /><br /> map<int,string> foo; // BANG!<br />---------------------------------------------------------------------<br /><br />Next, I try to use Photoshop Basic Suite:<br /><br />---------------------------------------------------------------------<br />#include <algorithm><br /><br />namespace std {}<br />using namespace std;<br /><br />#include <PIFormat.h><br /><br />extern SPBasicSuite *g_sSPBasic;<br /><br />inline void * operator new ( const size_t size )<br />{<br /> void *result = 0;<br /><br /> if( 0 != g_sSPBasic )<br /> {<br /> void *temp;<br /><br /> if( g_sSPBasic->AllocateBlock( size, &result ) )<br /> {<br /> result = 0;<br /> }<br /> else<br /> {<br />#ifdef DEBUG<br /> char *tmp = static_cast<char*>( result );<br /> fill( tmp, tmp + size, 0xEB );<br />#endif<br /> }<br /> }<br /><br /> return result;<br />}<br /><br />inline void operator delete ( void * ptr )<br />{<br /> if( 0 != g_sSPBasic )<br /> {<br /> g_sSPBasic->FreeBlock( ptr );<br /> }<br />}<br /><br />// the same for operator new[] and operator delete[]<br />---------------------------------------------------------------------<br /><br />Now simple STL collections can be created.<br /><br />Is there more laconic way to create STL collections?<br /><br />Moreover. This code is very dirty. For example, I even don't sure that Simple Suite address is constant between calls of plug-in entry point. So I think this is an awful dangerous code (just imagine the effect of two copies of of Adobe Photoshop using plug-in using this operators simultaneously).<br /><br />Do you have some ideas how to make it clean and working?
TOPICS
SDK

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Adobe Employee ,
Dec 19, 2007 Dec 19, 2007

Copy link to clipboard

Copied

Are you using PINew.h(cpp)? I would not use them and not override operator new and delete. You are probably having a mismatch of when the new and delete operators are getting executed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 19, 2007 Dec 19, 2007

Copy link to clipboard

Copied

1. don't create global objects!
2. standard operator new() can't return 0. throw std::bad_alloc instead

2 Pavel: welcome to developer[dog]akvis.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 19, 2007 Dec 19, 2007

Copy link to clipboard

Copied

2 Tom Ruark

Thanks for your support.

> Are you using PINew.h(cpp)?

What is PINew.h(cpp)? Yeah, I can guess that it's what I need.

I use Adobe Photoshop CS2 SDK. There are no files PINew*.*

To be more precise where can I find these files?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 20, 2007 Dec 20, 2007

Copy link to clipboard

Copied

2 all

On dynamic C++ memory management in Adobe Photoshop plug-in

As there are some people interested in the question I'll try to explain a technique I use at present.

I have two memory allocators:
a) based on Adobe's Basic Suite for small blocks (under 2Kbytes)
b) based on Adobe's Handle Suite for large blocks (above 2Kbytes)

operator new and operator new[] allocate 4 additional bytes for every allocation, store in the first 4 bytes handle to memory allocator used for this new or new[] call, and return pointer after this handle.

operator delete and operator delete[] takes memory allocator handle from the pre-pointer 4 bytes, and dellocate memory using correct memory allocator.

This strategy works well.

Does anybody know a better dynamic memory management technique to use with Adobe SDK for Adobe Photoshop plug-ins?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 20, 2007 Dec 20, 2007

Copy link to clipboard

Copied

If Photoshop Handle/Buffer suite unavailable, use malloc() instead, and store INVALID_HANDLE_VALUE in pre-pointer 4 bytes.

operator delete must compare stored handle with INVALID_HANDLE_VALUE and call Photoshop callbacks or free()

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 20, 2007 Dec 20, 2007

Copy link to clipboard

Copied

> If Photoshop Handle/Buffer suite unavailable, use malloc() instead

But malloc() always returns NULL in my tests. So I throw std::bad_alloc if Adobe's suites is unavailable.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 20, 2007 Dec 20, 2007

Copy link to clipboard

Copied

class Foo
{
public:
Foo() : ptr( new int[100] ) {}
~Foo() { delete [] ptr; }
private:
int * ptr;
};

Foo foo;

void PLUGIN_ENTRY_POINT(...

During DLL run-time startup, Foo::Foo called, and you don't have pointers to PS funcs at this point.
Result: Unhandled exception.

Many third-party libs have hidden global objects (managers, caches etc).

if you don't have suites, call malloc(). If malloc() return NULL, throw std::bad_alloc. And don't forgot to implement no-throw operator new.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 20, 2007 Dec 20, 2007

Copy link to clipboard

Copied

LATEST
2 Ivan Kharin

> Result: Unhandled exception.

You got the point!

The thing is I prefer to get an error diagnostic exactly at the time the problem occurs. As you know it grants us developers (and possibly our QA teams) more chances to efficiently work around the issue.

The another not least important reason is that unhandled exception at program startup is much-much-better then one after two and half hours of hard work.

> And don't forgot to implement no-throw operator new.

When I need it I will certanly do it.

Great thanks for your feedback.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines