Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Memory Allocation - Marshal ??
Message
From
24/04/2006 17:46:07
 
 
To
24/04/2006 17:08:37
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows NT
Miscellaneous
Thread ID:
01116042
Message ID:
01116141
Views:
22
This message has been marked as a message which has helped to the initial question of the thread.
Hello,

"Do you have any examples using them ?"
#INCLUDE vfp2c.h
SET PROCEDURE TO vfp2c.prg ADDITIVE
SET LIBRARY TO vfp2c32.fll ADDITIVE
INITVFP2C32(VFP2C_INIT_MARSHAL)

&& examples for marshaling arrays

&& create sample data for examples
LOCAL laArray[20]
FOR xj = 1 TO ALEN(laArray)
	laArray[xj] = 1000 * xj
ENDFOR

CREATE CURSOR testCursor(intField I, charField C(50))
FOR xj = 1 TO 20
	INSERT INTO testCursor VALUES (xj,'Hello C ' + ALLTRIM(STR(xj)))
ENDFOR

&& create the C style array class of the correct type
LOCAL loCArray
loCArray = CREATEOBJECT('CIntArray') && int/long
&& loCArray = CREATEOBJECT('CShortArray') && short
&& loCArray = CREATEOBJECT('CUShortArray') && unsigned short
&& loCArray = CREATEOBJECT('CUIntArray') && unsigned int/long
&& loCArray = CREATEOBJECT('CFloatArray') && float
&& loCArray = CREATEOBJECT('CDoubleArray') && double

&& marshal the FoxPro style array ( !!! pass array by reference !!!)
loCArray.MarshalArray(@laArray)

&& or marshal a field of a cursor ( !!! pass cursor.fieldname as a string !!!)
loCArray.MarshalCursor('testcursor.intField')

&& pass the C style array to some C function 
&& the Address property holds the pointer (memory address) of the C style array
&& someFunc(loCArray.Address)

&& if the array was altered by the function, unmarshal it back 
&& loCArray.UnMarshalArray(@laArray)

&& character arrays
&& C - char laArray[x][x];
loCArray = CREATEOBJECT('CCharArray')
loCArray.MarshalCursor('testcursor.charfield',50) 
loCArray.MarshalCursor('testcursor.charfield',30) && automatic truncation of field !!

&& C - char *laArray[x]; array of pointers to C strings
loCArray = CREATEOBJECT('CStringArray')
loCArray.MarshalCursor('testcursor.charfield')

&& manual construction of C style array - !! rather slow - if the C style array is bigger than a few elements 
&& its faster to create a FoxPro array first and then marshal it with MarshalArray 

loCArray = CREATEOBJECT('CStringArray')
loCArray.Dimension(10)
FOR xj = 1 TO loCArray.Elements
	loCArray.Element(xj) = 'Hello C ' + ALLTRIM(STR(xj))
ENDFOR

FOR xj = 1 TO loCArray.Elements
	? loCArray.Element(xj)
ENDFOR
loCArray = null
Regards
Christian
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform