11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

7.2 Using Compiled Code in Maple • 311> quadruple_it := define_external(’quadruple_it’,> WRAPPER,FILE="quad",> x::float[4],> RETURN::float[4],> LIB="test.dll"):> quadruple_it(2.2);8.80000019073486328> restart;> quadruple_it := define_external(’quadruple_it’,> WRAPPER,FILE="quad",> x::float[4],> RETURN::float[4],> WRAPLIB="quad.dll",> LIB="test.dll"):> quadruple_it(2.2);8.80000019073486328When DLLs are created and compiled at runtime it is important notto duplicate the name of a previously generated DLL without restartingMaple (either by exiting Maple or issuing the restart command). Maplemaintains an open connection with the first DLL opened with any givenname. Attempting to create a new DLL of the same name without restartingcan lead to unexpected results. The Maple command dlclose can beused to avoid restarting, but subsequently calling any external function inthat closed DLL without reissuing the define_external command willlikely crash Maple.Evaluation RulesExternal functions follow normal Maple evaluation rules in that the argumentsare evaluated during a function call. It therefore may be necessaryto enclose assigned names in right single quotes when passing-byreference.For example, consider the following function that multiplies anumber by two in-place.void double_it( int *i ){if( i == NULL ) return;}*i *= 2;In Maple, the wrapperless definition of this function might appear asfollows.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!