Skip to main content
Inspiring
February 24, 2017
Answered

Using the AIPathConstructionMemoryObject

  • February 24, 2017
  • 1 reply
  • 656 views

Hello,

I want to use the ReducePathSegments function from the Path Construction

Suite. The function requires an AIPathConstructionMemoryObject.

My Code looks like this:

AIPathConstructionMemoryObject *mem = new AIPathConstructionMemoryObject;

mem->allocate(500);

sAIPathConstruction->ReducePathSegments(art, factor, mem);

When mem->allocate(500) is called Adobe Illustrator throws the exception:

Access violation reading location 0xFFFFFFFFFFFFFFFF.

How do I use the AIPathConstructionMemoryObject correctly and how can I

determine how much memory ReducePathSegments needs?

Thanks

This topic has been closed for replies.
Correct answer LeoTaro

The allocate and dispose members of AIPathConstructionMemoryObject are pointers to functions that you have to provide, you could just use free and malloc as below:

            AIPathConstructionMemoryObject mem;

            mem.allocate = malloc;

            mem.dispose = free;

            sAIPathConstruction->ReducePathSegments(art, factor, &mem);

The comments in the header suggest you use wrapper functions around the SPBlocks functions as below (which would allow you to monitor how much memory they allocate):

void *mymalloc( size_t size )

{

    void *ptr = NULL;

    sSPBlocks->AllocateBlock(size,NULL,&ptr);

    return ptr;

}

void myfree( void *pointer )

{

    sSPBlocks->FreeBlock(pointer);

}

    AIPathConstructionMemoryObject mem;

    mem.allocate = mymalloc;

    mem.dispose = myfree;

    sAIPathConstruction->ReducePathSegments(art, factor, &mem);

1 reply

LeoTaroCorrect answer
Inspiring
February 26, 2017

The allocate and dispose members of AIPathConstructionMemoryObject are pointers to functions that you have to provide, you could just use free and malloc as below:

            AIPathConstructionMemoryObject mem;

            mem.allocate = malloc;

            mem.dispose = free;

            sAIPathConstruction->ReducePathSegments(art, factor, &mem);

The comments in the header suggest you use wrapper functions around the SPBlocks functions as below (which would allow you to monitor how much memory they allocate):

void *mymalloc( size_t size )

{

    void *ptr = NULL;

    sSPBlocks->AllocateBlock(size,NULL,&ptr);

    return ptr;

}

void myfree( void *pointer )

{

    sSPBlocks->FreeBlock(pointer);

}

    AIPathConstructionMemoryObject mem;

    mem.allocate = mymalloc;

    mem.dispose = myfree;

    sAIPathConstruction->ReducePathSegments(art, factor, &mem);

owitaAuthor
Inspiring
February 27, 2017

Many thanks to LeoTaro!