README.md (2687B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # Maximum Array Length 22 23 > Maximum length for a generic array. 24 25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 26 27 <section class="intro"> 28 29 </section> 30 31 <!-- /.intro --> 32 33 <!-- Package usage documentation. --> 34 35 <section class="usage"> 36 37 ## Usage 38 39 ```javascript 40 var MAX_ARRAY_LENGTH = require( '@stdlib/constants/array/max-array-length' ); 41 ``` 42 43 #### MAX_ARRAY_LENGTH 44 45 Maximum length for a generic array. 46 47 ```javascript 48 var len = MAX_ARRAY_LENGTH; 49 // returns 4294967295 50 ``` 51 52 </section> 53 54 <!-- /.usage --> 55 56 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 57 58 <section class="notes"> 59 60 </section> 61 62 <!-- /.notes --> 63 64 <!-- Package usage examples. --> 65 66 <section class="examples"> 67 68 ## Examples 69 70 <!-- eslint no-undef: "error" --> 71 72 ```javascript 73 var MAX_ARRAY_LENGTH = require( '@stdlib/constants/array/max-array-length' ); 74 75 function alloc( len ) { 76 var arr; 77 var i; 78 if ( len > MAX_ARRAY_LENGTH ) { 79 throw new RangeError( 'invalid argument. The maximum length for a generic array is '+MAX_ARRAY_LENGTH+'. To create a longer array-like data structure, consider either typed arrays or an array-like object.' ); 80 } 81 // Manually allocate to ensure "fast" elements... 82 arr = []; 83 for ( i = 0; i < len; i++ ) { 84 arr.push( 0 ); 85 } 86 return arr; 87 } 88 89 var arr = alloc( 10 ); 90 console.log( arr ); 91 92 try { 93 arr = alloc( 1e300 ); 94 } catch ( err ) { 95 console.error( err.message ); 96 } 97 ``` 98 99 </section> 100 101 <!-- /.examples --> 102 103 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 104 105 <section class="references"> 106 107 </section> 108 109 <!-- /.references --> 110 111 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 112 113 <section class="links"> 114 115 </section> 116 117 <!-- /.links -->