BVB Source Codes

jsfeat Show jsfeat_cache.js Source code

Return Download jsfeat: download jsfeat_cache.js Source code - Download jsfeat Source code - Type:.js
  1. /**
  2.  * @author Eugene Zatepyakin / http://inspirit.ru/
  3.  */
  4.  
  5. (function(global) {
  6.     "use strict";
  7.     //
  8.  
  9.     var cache = (function() {
  10.  
  11.         // very primitive array cache, still need testing if it helps
  12.         // of course V8 has its own powerful cache sys but i'm not sure
  13.         // it caches several multichannel 640x480 buffer creations each frame
  14.  
  15.         var _pool_node_t = (function () {
  16.             function _pool_node_t(size_in_bytes) {
  17.                 this.next = null;
  18.                 this.data = new jsfeat.data_t(size_in_bytes);
  19.                 this.size = this.data.size;
  20.                 this.buffer = this.data.buffer;
  21.                 this.u8 = this.data.u8;
  22.                 this.i32 = this.data.i32;
  23.                 this.f32 = this.data.f32;
  24.                 this.f64 = this.data.f64;
  25.             }
  26.             _pool_node_t.prototype.resize = function(size_in_bytes) {
  27.                 delete this.data;
  28.                 this.data = new jsfeat.data_t(size_in_bytes);
  29.                 this.size = this.data.size;
  30.                 this.buffer = this.data.buffer;
  31.                 this.u8 = this.data.u8;
  32.                 this.i32 = this.data.i32;
  33.                 this.f32 = this.data.f32;
  34.                 this.f64 = this.data.f64;
  35.             }
  36.             return _pool_node_t;
  37.         })();
  38.  
  39.         var _pool_head, _pool_tail;
  40.         var _pool_size = 0;
  41.  
  42.         return {
  43.  
  44.             allocate: function(capacity, data_size) {
  45.                 _pool_head = _pool_tail = new _pool_node_t(data_size);
  46.                 for (var i = 0; i < capacity; ++i) {
  47.                     var node = new _pool_node_t(data_size);
  48.                     _pool_tail = _pool_tail.next = node;
  49.  
  50.                     _pool_size++;
  51.                 }
  52.             },
  53.  
  54.             get_buffer: function(size_in_bytes) {
  55.                 // assume we have enough free nodes
  56.                 var node = _pool_head;
  57.                 _pool_head = _pool_head.next;
  58.                 _pool_size--;
  59.  
  60.                 if(size_in_bytes > node.size) {
  61.                     node.resize(size_in_bytes);
  62.                 }
  63.  
  64.                 return node;
  65.             },
  66.  
  67.             put_buffer: function(node) {
  68.                 _pool_tail = _pool_tail.next = node;
  69.                 _pool_size++;
  70.             }
  71.         };
  72.     })();
  73.  
  74.     global.cache = cache;
  75.     // for now we dont need more than 30 buffers
  76.     // if having cache sys really helps we can add auto extending sys
  77.     cache.allocate(30, 640*4);
  78.  
  79. })(jsfeat);
  80.  
downloadjsfeat_cache.js Source code - Download jsfeat Source code
Related Source Codes/Software:
flakes - Flakes is an Admin Template Framework. A combinati... 2017-04-15
capstone - Capstone disassembly/disassembler framework: Core ... 2017-04-15
nginx-resources - A collection of resources covering Nginx, Nginx + ... 2017-04-15
utron - A lightweight MVC framework for Go(Golang) 2017-04-15
cfssl - CFSSL: Cloudflare's PKI and TLS toolkit ... 2017-04-15
MLeaksFinder - Find memory leaks in your iOS app at develop time. 2017-04-16
qt - Qt binding for Go (Golang) which supports Windows ... 2017-04-16
rainloop-webmail - Simple, modern & fast web-based email client ... 2017-04-16
pencil - Multiplatform GUI Prototyping/Wireframing 2017-04-16
x64dbg - An open-source x64/x32 debugger for windows. ... 2017-04-16
Toucan - Fabulous Image Processing in Swift 2017-04-23
CoffeeScriptRedux - 2017-04-23
breakpoint - Really simple media queries in Sa 2017-04-23
libsvm - 2017-04-22
grr - GRR Rapid Response: remote live forensics for inci... 2017-04-22
grit - **Grit is no longer maintained. Check out libgit2/... 2017-04-22
guard-livereload - Guard::LiveReload automatically reload your browse... 2017-04-22
Begin-Latex-in-minutes - Brief Intro to LaTeX for beginners that helps you ... 2017-04-22
wicked - Use wicked to turn your controller into a wizard ... 2017-04-22
flexboxfroggy - A game for learning CSS flexbox ... 2017-04-22

 Back to top