Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
v8::ArrayBuffer::Allocator Class Referenceabstract

#include <v8-array-buffer.h>

Public Types

enum class  AllocationMode { kNormal , kReservation }
 

Public Member Functions

virtual ~Allocator ()=default
 
virtual void * Allocate (size_t length)=0
 
virtual void * AllocateUninitialized (size_t length)=0
 
virtual void Free (void *data, size_t length)=0
 
virtual void * Reallocate (void *data, size_t old_length, size_t new_length)
 

Static Public Member Functions

static AllocatorNewDefaultAllocator ()
 

Detailed Description

A thread-safe allocator that V8 uses to allocate |ArrayBuffer|'s memory. The allocator is a global V8 setting. It has to be set via Isolate::CreateParams.

Memory allocated through this allocator by V8 is accounted for as external memory by V8. Note that V8 keeps track of the memory for all internalized |ArrayBuffer|s. Responsibility for tracking external memory (using Isolate::AdjustAmountOfExternalAllocatedMemory) is handed over to the embedder upon externalization and taken over upon internalization (creating an internalized buffer from an existing buffer).

Note that it is unsafe to call back into V8 from any of the allocator functions.

Member Enumeration Documentation

◆ AllocationMode

ArrayBuffer allocation mode. kNormal is a malloc/free style allocation, while kReservation is for larger allocations with the ability to set access permissions.

Enumerator
kNormal 
kReservation 

Constructor & Destructor Documentation

◆ ~Allocator()

virtual v8::ArrayBuffer::Allocator::~Allocator ( )
virtualdefault

Member Function Documentation

◆ Allocate()

virtual void * v8::ArrayBuffer::Allocator::Allocate ( size_t  length)
pure virtual

Allocate |length| bytes. Return nullptr if allocation is not successful. Memory should be initialized to zeroes.

◆ AllocateUninitialized()

virtual void * v8::ArrayBuffer::Allocator::AllocateUninitialized ( size_t  length)
pure virtual

Allocate |length| bytes. Return nullptr if allocation is not successful. Memory does not have to be initialized.

◆ Free()

virtual void v8::ArrayBuffer::Allocator::Free ( void *  data,
size_t  length 
)
pure virtual

Free the memory block of size |length|, pointed to by |data|. That memory is guaranteed to be previously allocated by |Allocate|.

◆ NewDefaultAllocator()

static Allocator * v8::ArrayBuffer::Allocator::NewDefaultAllocator ( )
static

Convenience allocator.

When the sandbox is enabled, this allocator will allocate its backing memory inside the sandbox. Otherwise, it will rely on malloc/free.

Caller takes ownership, i.e. the returned object needs to be freed using |delete allocator| once it is no longer in use.

Examples
process.cc, and shell.cc.

◆ Reallocate()

virtual void * v8::ArrayBuffer::Allocator::Reallocate ( void *  data,
size_t  old_length,
size_t  new_length 
)
virtual

Reallocate the memory block of size |old_length| to a memory block of size |new_length| by expanding, contracting, or copying the existing memory block. If |new_length| > |old_length|, then the new part of the memory must be initialized to zeros. Return nullptr if reallocation is not successful.

The caller guarantees that the memory block was previously allocated using Allocate or AllocateUninitialized.

The default implementation allocates a new block and copies data.


The documentation for this class was generated from the following file: