arrow_back_ios Back to List

Caching instance data

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.

The code below caches the this pointer only by using a local temporary object on the SPU, copies data from the PPU via DMA or Software Cache into that object and calls the (duplicated) method func on it with 2 PPU pointer arguments.

	auto localptr = *ptr; //DMA or SW cache read into a local
	localptr.func(ptrarg1,ptrarg2);//__inner this pointer and outer argument pointers* ptr
	*ptr = localptr; //writing data back

This means that all fields of the instance are now in fast local memory. The write-back at the end may not be necessary if func is a const-qualified member function (doesn't modify the SPU local instance). In fact if any code before the write-back causes side-effects to the (PPU) data that ptr points to, the a single write-back would clobber these changes.

This caching required changes to existing code which may not be practical when offloading larger chunks of code. The next /kb/136.html describes how to minimise those changes by using standard C++ cache classes.