Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- A value to pre-fill the new with.
- If is a string, this is its encoding.
- If is, the will be zero-filled
- If is specified, the allocated will be initialized by calling
- If both and are specified, the allocated will be initialized by calling
- Calling can be significantly slower than the alternative but ensures that the newly created instance contents will never contain sensitive data
- A will be thrown if is not a number.
- The underlying memory for instances created in this way is not initialized
- The contents of the newly created are unknown and may contain sensitive data
- Use instead to initialize instances with zeroes.
- Note that the module pre-allocates an internal instance of size that is used as a pool for the fast allocation of new instances created using and the deprecated constructor only when is less than or equal to (floor of divided by two).
- Use of this pre-allocated internal memory pool is a key difference between calling vs.
- Specifically, will never use the internal pool, while will use the internal pool if is less than or equal to half
- The difference is subtle but can be important when an application requires the additional performance that provides.
- Use to initialize such instances with zeroes.
- When using to allocate new instances, allocations under 4KB are sliced from a single pre-allocated
- This allows applications to avoid the garbage collection overhead of creating many individually allocated instances.
- This approach improves both performance and memory usage by eliminating the need to track and clean up as many persistent objects.
- However, in the case where a developer may need to retain a small chunk of memory from a pool for an indeterminate amount of time, it may be appropriate to create an un-pooled instance using and then copying out the relevant bits.
- Need to keep around a few small chunks of memory
- Allocate for retained data
- Copy the data into the new allocation
- should be used only as a last resort after a developer has observed undue memory retention in their applications.
- A value to calculate the length of.
- The number of bytes contained within
- Returns the actual byte length of a string.
- This is not the same as since that returns the number of characters in a string.
- For and, this function assumes valid input.
- For strings that contain encoded data (e.g. whitespace), the return value might be greater than the length of a created from the string.
- When is a, the actual byte length is returned.
- Compares to typically for the purpose of sorting arrays of instances.
- This is equivalent to calling
- List of or instances to concat.
- Total length of the instances in when concatenated.
- Returns a new which is the result of concatenating all the instances in the together.
- If the list has no items, or if the is 0, then a new zero-length is returned.
- If is not provided, it is calculated from the instances in
- This however causes an additional loop to be executed in order to calculate the, so it is faster to provide the length explicitly if it is already known.
- If is provided, it is coerced to an unsigned integer.
- If the combined length of the in exceeds, the result is truncated to
- // Create a single from a list of three instances.
- A will be thrown if is not an
- This creates a view of the without copying the underlying memory.
- For example, when passed a reference to the property of a instance, the newly created will share the same allocated memory as the
- A will be thrown if is not an or a
- A string to encode.
- An object supporting or
- A byte-offset or encoding, depending on the value returned either by or
- A length, depending on the value returned either by or
- For objects whose function returns a value not strictly equal to, returns
- For objects that support, returns
- Returns if is a, otherwise.
- A character encoding name to check.
- Returns if contains a supported character encoding, or otherwise
- This is the size (in bytes) of pre-allocated internal instances used for pooling.
- This value may be modified.
- The index operator can be used to get and set the octet at position in
- The values refer to individual bytes, so the legal value range is between and (hex) or and (decimal)
- This operator is inherited from, so its behavior on out-of-bounds access is the same as - that is, getting returns and setting does nothing.
- // Copy an ASCII string into a one byte at a time.
- The underlying object based on which this object is created.
- A or with which to compare
- The offset within at which to begin comparison.
- Compares with and returns a number indicating whether comes before, after, or is the same as in sort order.
- Comparison is based on the actual sequence of bytes in each
- is returned if is the same as
- is returned if should come before when sorted.
- The optional and, arguments can be used to limit the comparison to specific ranges within and respectively.
- is thrown if, or
- A or to copy into.
- The offset within at which to begin writing.
- The number of bytes copied.
- Copies data from a region of to a region in even if the memory region overlaps with
- // Create two `Buffer` instances.
- 97 is the decimal ASCII value for
- Copy bytes 16 through 19 into starting at byte 8 of
- // Create a and copy data from one region to an overlapping region within the same
- Creates and returns an iterator of pairs from the contents of
- // Log the entire contents of a
- Returns if both and have exactly the same bytes, otherwise.
- The value with which to fill
- Number of bytes to skip before starting to fill
- Where to stop filling (not inclusive).
- The encoding for if is a string.
- A reference to
- Fills with the specified
- If the and are not given, the entire will be filled:
- // Fill a with the ASCII character
- is coerced to a value if it is not a string or integer.
- If the final write of a operation falls on a multi-byte character, then only the bytes of that character that fit into are written:
- // Fill a with a two-byte character.
- If contains invalid characters, it is truncated; if no valid fill data remains, an exception is thrown:
- Throws an exception
Add Comment
Please, Sign In to add comment