repl.txt (9042B)
1 2 {{alias}}( [dtype] ) 3 Returns an uninitialized typed array from a typed array memory pool. 4 5 Memory is **uninitialized**, which means that the contents of a returned 6 typed array may contain sensitive contents. 7 8 The function supports the following data types: 9 10 - float64: double-precision floating-point numbers (IEEE 754) 11 - float32: single-precision floating-point numbers (IEEE 754) 12 - int32: 32-bit two's complement signed integers 13 - uint32: 32-bit unsigned integers 14 - int16: 16-bit two's complement signed integers 15 - uint16: 16-bit unsigned integers 16 - int8: 8-bit two's complement signed integers 17 - uint8: 8-bit unsigned integers 18 - uint8c: 8-bit unsigned integers clamped to 0-255 19 20 The default typed array data type is `float64`. 21 22 Parameters 23 ---------- 24 dtype: string (optional) 25 Data type. Default: 'float64'. 26 27 Returns 28 ------- 29 out: TypedArray|null 30 If the function is unable to allocate a typed array from the typed array 31 pool (e.g., due to insufficient memory), the function returns `null`. 32 33 Examples 34 -------- 35 > var arr = {{alias}}() 36 <Float64Array>[] 37 > arr = {{alias}}( 'float32' ) 38 <Float32Array>[] 39 40 41 {{alias}}( length[, dtype] ) 42 Returns an uninitialized typed array having a specified length from a typed 43 array memory pool. 44 45 Parameters 46 ---------- 47 length: integer 48 Typed array length. 49 50 dtype: string (optional) 51 Data type. Default: 'float64'. 52 53 Returns 54 ------- 55 out: TypedArray|null 56 If the function is unable to allocate a typed array from the typed array 57 pool (e.g., due to insufficient memory), the function returns `null`. 58 59 Examples 60 -------- 61 > var arr = {{alias}}( 5 ) 62 <Float64Array> 63 > arr = {{alias}}( 5, 'int32' ) 64 <Int32Array> 65 66 67 {{alias}}( typedarray[, dtype] ) 68 Creates a pooled typed array from another typed array. 69 70 Parameters 71 ---------- 72 typedarray: TypedArray 73 Typed array from which to generate another typed array. 74 75 dtype: string (optional) 76 Data type. Default: 'float64'. 77 78 Returns 79 ------- 80 out: TypedArray|null 81 If the function is unable to allocate a typed array from the typed array 82 pool (e.g., due to insufficient memory), the function returns `null`. 83 84 Examples 85 -------- 86 > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); 87 > var arr2 = {{alias}}( arr1, 'float32' ) 88 <Float32Array>[ 0.5, 0.5, 0.5 ] 89 90 91 {{alias}}( obj[, dtype] ) 92 Creates a pooled typed array from an array-like object. 93 94 Parameters 95 ---------- 96 obj: Object 97 Array-like object from which to generate a typed array. 98 99 dtype: string (optional) 100 Data type. Default: 'float64'. 101 102 Returns 103 ------- 104 out: TypedArray|null 105 If the function is unable to allocate a typed array from the typed array 106 pool (e.g., due to insufficient memory), the function returns `null`. 107 108 Examples 109 -------- 110 > var arr1 = [ 0.5, 0.5, 0.5 ]; 111 > var arr2 = {{alias}}( arr1, 'float32' ) 112 <Float32Array>[ 0.5, 0.5, 0.5 ] 113 114 115 {{alias}}.malloc( [dtype] ) 116 Returns an uninitialized typed array from a typed array memory pool. 117 118 This method shares the same security vulnerabilities mentioned above. 119 120 Parameters 121 ---------- 122 dtype: string (optional) 123 Data type. Default: 'float64'. 124 125 Returns 126 ------- 127 out: TypedArray|null 128 If the function is unable to allocate a typed array from the typed array 129 pool (e.g., due to insufficient memory), the function returns `null`. 130 131 Examples 132 -------- 133 > var arr = {{alias}}.malloc() 134 <Float64Array> 135 > arr = {{alias}}.malloc( 'float32' ) 136 <Float32Array> 137 138 139 {{alias}}.malloc( length[, dtype] ) 140 Returns a typed array having a specified length from a typed array memory 141 pool. 142 143 Parameters 144 ---------- 145 length: integer 146 Typed array length. 147 148 dtype: string (optional) 149 Data type. Default: 'float64'. 150 151 Returns 152 ------- 153 out: TypedArray|null 154 If the function is unable to allocate a typed array from the typed array 155 pool (e.g., due to insufficient memory), the function returns `null`. 156 157 Examples 158 -------- 159 > var arr = {{alias}}.malloc( 5 ) 160 <Float64Array> 161 > arr = {{alias}}.malloc( 5, 'int32' ) 162 <Int32Array> 163 164 165 {{alias}}.malloc( typedarray[, dtype] ) 166 Creates a pooled typed array from another typed array. 167 168 Parameters 169 ---------- 170 typedarray: TypedArray 171 Typed array from which to generate another typed array. 172 173 dtype: string (optional) 174 Data type. Default: 'float64'. 175 176 Returns 177 ------- 178 out: TypedArray|null 179 If the function is unable to allocate a typed array from the typed array 180 pool (e.g., due to insufficient memory), the function returns `null`. 181 182 Examples 183 -------- 184 > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); 185 > var arr2 = {{alias}}.malloc( arr1, 'float32' ) 186 <Float32Array>[ 0.5, 0.5, 0.5 ] 187 188 189 {{alias}}.malloc( obj[, dtype] ) 190 Creates a pooled typed array from an array-like object. 191 192 Parameters 193 ---------- 194 obj: Object 195 Array-like object from which to generate a typed array. 196 197 dtype: string (optional) 198 Data type. Default: 'float64'. 199 200 Returns 201 ------- 202 out: TypedArray|null 203 If the function is unable to allocate a typed array from the typed array 204 pool (e.g., due to insufficient memory), the function returns `null`. 205 206 Examples 207 -------- 208 > var arr1 = [ 0.5, 0.5, 0.5 ]; 209 > var arr2 = {{alias}}.malloc( arr1, 'float32' ) 210 <Float32Array>[ 0.5, 0.5, 0.5 ] 211 212 213 {{alias}}.calloc( [dtype] ) 214 Returns a zero-initialized typed array from a typed array memory pool. 215 216 Parameters 217 ---------- 218 dtype: string (optional) 219 Data type. Default: 'float64'. 220 221 Returns 222 ------- 223 out: TypedArray|null 224 If the function is unable to allocate a typed array from the typed array 225 pool (e.g., due to insufficient memory), the function returns `null`. 226 227 Examples 228 -------- 229 > var arr = {{alias}}.calloc() 230 <Float64Array>[] 231 > arr = {{alias}}.calloc( 'float32' ) 232 <Float32Array>[] 233 234 235 {{alias}}.calloc( length[, dtype] ) 236 Returns a zero-initialized typed array having a specified length from a 237 typed array memory pool. 238 239 Parameters 240 ---------- 241 length: integer 242 Typed array length. 243 244 dtype: string (optional) 245 Data type. Default: 'float64'. 246 247 Returns 248 ------- 249 out: TypedArray|null 250 If the function is unable to allocate a typed array from the typed array 251 pool (e.g., due to insufficient memory), the function returns `null`. 252 253 Examples 254 -------- 255 > var arr = {{alias}}.calloc( 5 ) 256 <Float64Array>[ 0.0, 0.0, 0.0, 0.0, 0.0 ] 257 > arr = {{alias}}.calloc( 5, 'int32' ) 258 <Int32Array>[ 0, 0, 0, 0, 0 ] 259 260 261 {{alias}}.free( buf ) 262 Frees a typed array or typed array buffer for use in a future allocation. 263 264 Parameters 265 ---------- 266 buf: TypedArray|ArrayBuffer 267 Typed array or typed array buffer to free. 268 269 Examples 270 -------- 271 > var arr = {{alias}}( 5 ) 272 <Float64Array> 273 > {{alias}}.free( arr ) 274 275 276 {{alias}}.clear() 277 Clears the typed array pool allowing garbage collection of previously 278 allocated (and currently free) array buffers. 279 280 Examples 281 -------- 282 > var arr = {{alias}}( 5 ) 283 <Float64Array> 284 > {{alias}}.free( arr ); 285 > {{alias}}.clear() 286 287 288 {{alias}}.highWaterMark 289 Read-only property returning the pool's high water mark. 290 291 Once a high water mark is reached, typed array allocation fails. 292 293 Examples 294 -------- 295 > {{alias}}.highWaterMark 296 297 298 {{alias}}.nbytes 299 Read-only property returning the total number of allocated bytes. 300 301 The returned value is the total accumulated value. Hence, anytime a pool 302 must allocate a new array buffer (i.e., more memory), the pool increments 303 this value. 304 305 The only time this value is decremented is when a pool is cleared. 306 307 This behavior means that, while allocated buffers which are never freed may, 308 in fact, be garbage collected, they continue to count against the high water 309 mark limit. 310 311 Accordingly, you should *always* free allocated buffers in order to prevent 312 the pool from believing that non-freed buffers are continually in use. 313 314 Examples 315 -------- 316 > var arr = {{alias}}( 5 ) 317 <Float64Array> 318 > {{alias}}.nbytes 319 320 321 {{alias}}.factory( [options] ) 322 Creates a typed array pool. 323 324 Parameters 325 ---------- 326 options: Object (optional) 327 Function options. 328 329 options.highWaterMark: integer (optional) 330 Maximum total memory (in bytes) which can be allocated. 331 332 Returns 333 ------- 334 fcn: Function 335 Function for creating typed arrays from a typed array memory pool. 336 337 Examples 338 -------- 339 > var pool = {{alias}}.factory(); 340 > var arr1 = pool( 3, 'float64' ) 341 <Float64Array> 342 343 See Also 344 -------- 345