Advertisement
Drakim

Haxe memset

Mar 10th, 2013
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 1.35 KB | None | 0 0
  1.   /* writeIntPattern() aka memset() */
  2.   public inline function writeIntPattern(_pattern:Int,_offset:Int,_length:Int):Void {
  3.     /* write our Int pattern twice */
  4.     write32(_pattern,_offset);
  5.     write32(_pattern,_offset+4);
  6.    
  7.     /* get the float version of our pattern */
  8.     var value = read64(_offset);
  9.    
  10.     /* we decide how far to write our pattern with write64, max 600 bytes */
  11.     var position = IntMath.min(600,_length);
  12.    
  13.     /* the loop is backwards and ends within the last 8 bytes because they are already written */
  14.     while((position-=8)>0) {write64(value,_offset+position);}
  15.    
  16.     var distance = 600;
  17.     var copylength = 600;
  18.    
  19.     /* now that we have 600 bytes written, we start using writeBytes to mass copy the bytes */
  20.     while(_length>distance) {
  21.       /* AlchemyManager sold seperately */
  22.       platform.flash.utils.AlchemyManager.bytearray.position = address+distance;
  23.       platform.flash.utils.AlchemyManager.bytearray.writeBytes(platform.flash.utils.AlchemyManager.bytearray,address,copylength);
  24.      
  25.       /* the next mass copy will be twice as big, eg 600->1200->2400->4800->etc */
  26.       distance*=2;
  27.       copylength*=2;
  28.      
  29.       /* in case the next mass copy will spill over the length, we need to clamp the copylength here */
  30.       copylength=IntMath.min(_length-copylength,copylength);
  31.     }
  32.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement