Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
fml::MallocMapping Class Referencefinal

A Mapping like NonOwnedMapping, but uses Free as its release proc. More...

#include <mapping.h>

Inheritance diagram for fml::MallocMapping:
fml::Mapping

Public Member Functions

 MallocMapping ()
 
 MallocMapping (uint8_t *data, size_t size)
 
 MallocMapping (fml::MallocMapping &&mapping)
 
 ~MallocMapping () override
 
size_t GetSize () const override
 
const uint8_t * GetMapping () const override
 
bool IsDontNeedSafe () const override
 
uint8_t * Release ()
 
- Public Member Functions inherited from fml::Mapping
 Mapping ()
 
virtual ~Mapping ()
 
virtual size_t GetSize () const =0
 
virtual const uint8_t * GetMapping () const =0
 
virtual bool IsDontNeedSafe () const =0
 

Static Public Member Functions

template<typename T >
static MallocMapping Copy (const T *begin, const T *end)
 
static MallocMapping Copy (const void *begin, size_t length)
 

Detailed Description

A Mapping like NonOwnedMapping, but uses Free as its release proc.

Definition at line 144 of file mapping.h.

Constructor & Destructor Documentation

◆ MallocMapping() [1/3]

fml::MallocMapping::MallocMapping ( )

Definition at line 119 of file mapping.cc.

119: data_(nullptr), size_(0) {}

◆ MallocMapping() [2/3]

fml::MallocMapping::MallocMapping ( uint8_t *  data,
size_t  size 
)

Creates a MallocMapping for a region of memory (without copying it). The function will abort() if the malloc fails.

Parameters
dataThe starting address of the mapping.
sizeThe size of the mapping in bytes.

Definition at line 121 of file mapping.cc.

122 : data_(data), size_(size) {}
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ MallocMapping() [3/3]

fml::MallocMapping::MallocMapping ( fml::MallocMapping &&  mapping)

Definition at line 124 of file mapping.cc.

125 : data_(mapping.data_), size_(mapping.size_) {
126 mapping.data_ = nullptr;
127 mapping.size_ = 0;
128}

◆ ~MallocMapping()

fml::MallocMapping::~MallocMapping ( )
override

Definition at line 130 of file mapping.cc.

130 {
131 free(data_);
132 data_ = nullptr;
133}

Member Function Documentation

◆ Copy() [1/2]

template<typename T >
static MallocMapping fml::MallocMapping::Copy ( const T begin,
const T end 
)
inlinestatic

Copies the data from begin to end. It's templated since void* arithemetic isn't allowed and we want support for uint8_t and char.

Definition at line 162 of file mapping.h.

162 {
163 FML_DCHECK(end >= begin);
164 size_t length = end - begin;
165 return Copy(begin, length);
166 }
static MallocMapping Copy(const T *begin, const T *end)
Definition: mapping.h:162
static const char * begin(const StringSlice &s)
Definition: editor.cpp:252
glong glong end
#define FML_DCHECK(condition)
Definition: logging.h:103
size_t length

◆ Copy() [2/2]

MallocMapping fml::MallocMapping::Copy ( const void *  begin,
size_t  length 
)
static

Copies a region of memory into a MallocMapping. The function will abort() if the malloc fails.

Parameters
beginThe starting address of where we will copy.
lengthThe length of the region to copy in bytes.

Definition at line 135 of file mapping.cc.

135 {
136 auto result =
137 MallocMapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
138 FML_CHECK(result.GetMapping() != nullptr);
139 memcpy(const_cast<uint8_t*>(result.GetMapping()), begin, length);
140 return result;
141}
GAsyncResult * result
#define FML_CHECK(condition)
Definition: logging.h:85
void * malloc(size_t size)
Definition: allocation.cc:19

◆ GetMapping()

const uint8_t * fml::MallocMapping::GetMapping ( ) const
overridevirtual

Implements fml::Mapping.

Definition at line 147 of file mapping.cc.

147 {
148 return data_;
149}

◆ GetSize()

size_t fml::MallocMapping::GetSize ( ) const
overridevirtual

Implements fml::Mapping.

Definition at line 143 of file mapping.cc.

143 {
144 return size_;
145}

◆ IsDontNeedSafe()

bool fml::MallocMapping::IsDontNeedSafe ( ) const
overridevirtual

Implements fml::Mapping.

Definition at line 151 of file mapping.cc.

151 {
152 return false;
153}

◆ Release()

uint8_t * fml::MallocMapping::Release ( )

Removes ownership of the data buffer. After this is called; the mapping will point to nullptr.

Definition at line 155 of file mapping.cc.

155 {
156 uint8_t* result = data_;
157 data_ = nullptr;
158 size_ = 0;
159 return result;
160}

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