arrow_back_ios Back to List

Offloading a simple method call

Offload KB - case-studies

Old Content Alert

Please note that this is a old document archive and the will most likely be out-dated or superseded by various other products and is purely here for historical purposes.

One of the most common Offload scenarios is calling a function on the SPU (i.e. inside an Offload context). For example:

__offload()
{
	ptr->func(ptrarg1,ptrarg2);//__outer this and argument pointers
}

The instance method func is called on a PPU pointer with 2 PPU pointers as arguments. There may be a performance penalty if method func, or functions it calls (directly or indirectly), frequently processes data off the argument pointers or the this pointer. In that case it might be worthwhile caching the data those pointers point to. This of course is subject to the usual language rules1, side-effects and enough SPU memory being available (usually on the SPU stack). Essentially, we want to emulate passing data by value to the SPU and for PPU pointer arguments this means caching data in local storage and using a pointer to local storage instead.

Read next article /kb/135.html about how to cache data.

1Caching usually involves allocating local storage by creating temporary variables. Variables of type void or structure type with abstract methods cannot be created.