Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkAutoSMalloc< kSizeRequested > Class Template Reference

#include <SkAutoMalloc.h>

Inheritance diagram for SkAutoSMalloc< kSizeRequested >:
SkNoncopyable

Public Member Functions

 SkAutoSMalloc ()
 
 SkAutoSMalloc (size_t size)
 
 ~SkAutoSMalloc ()
 
void * get () const
 
void * reset (size_t size, SkAutoMalloc::OnShrink shrink=SkAutoMalloc::kAlloc_OnShrink, bool *didChangeAlloc=nullptr)
 

Detailed Description

template<size_t kSizeRequested>
class SkAutoSMalloc< kSizeRequested >

Manage an allocated block of memory. If the requested size is <= kSizeRequested (or slightly more), then the allocation will come from the stack rather than the heap. This object is the sole manager of the lifetime of the block, so the caller must not call sk_free() or delete on the block.

Definition at line 90 of file SkAutoMalloc.h.

Constructor & Destructor Documentation

◆ SkAutoSMalloc() [1/2]

template<size_t kSizeRequested>
SkAutoSMalloc< kSizeRequested >::SkAutoSMalloc ( )
inline

Creates initially empty storage. get() returns a ptr, but it is to a zero-byte allocation. Must call reset(size) to return an allocated block.

Definition at line 96 of file SkAutoMalloc.h.

96 {
97 fPtr = fStorage;
98 fSize = kSize;
99 }

◆ SkAutoSMalloc() [2/2]

template<size_t kSizeRequested>
SkAutoSMalloc< kSizeRequested >::SkAutoSMalloc ( size_t  size)
inlineexplicit

Allocate a block of the specified size. If size <= kSizeRequested (or slightly more), then the allocation will come from the stack, otherwise it will be dynamically allocated.

Definition at line 105 of file SkAutoMalloc.h.

105 {
106 fPtr = fStorage;
107 fSize = kSize;
108 this->reset(size);
109 }
void * reset(size_t size, SkAutoMalloc::OnShrink shrink=SkAutoMalloc::kAlloc_OnShrink, bool *didChangeAlloc=nullptr)
Definition: SkAutoMalloc.h:133
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ ~SkAutoSMalloc()

template<size_t kSizeRequested>
SkAutoSMalloc< kSizeRequested >::~SkAutoSMalloc ( )
inline

Free the allocated block (if any). If the block was small enough to have been allocated on the stack, then this does nothing.

Definition at line 115 of file SkAutoMalloc.h.

115 {
116 if (fPtr != (void*)fStorage) {
117 sk_free(fPtr);
118 }
119 }
SK_API void sk_free(void *)

Member Function Documentation

◆ get()

template<size_t kSizeRequested>
void * SkAutoSMalloc< kSizeRequested >::get ( ) const
inline

Return the allocated block. May return non-null even if the block is of zero size. Since this may be on the stack or dynamically allocated, the caller must not call sk_free() on it, but must rely on SkAutoSMalloc to manage it.

Definition at line 126 of file SkAutoMalloc.h.

126{ return fPtr; }

◆ reset()

template<size_t kSizeRequested>
void * SkAutoSMalloc< kSizeRequested >::reset ( size_t  size,
SkAutoMalloc::OnShrink  shrink = SkAutoMalloc::kAlloc_OnShrink,
bool *  didChangeAlloc = nullptr 
)
inline

Return a new block of the requested size, freeing (as necessary) any previously allocated block. As with the constructor, if size <= kSizeRequested (or slightly more) then the return block may be allocated locally, rather than from the heap.

Definition at line 133 of file SkAutoMalloc.h.

135 {
136 size = (size < kSize) ? kSize : size;
137 bool alloc = size != fSize && (SkAutoMalloc::kAlloc_OnShrink == shrink || size > fSize);
138 if (didChangeAlloc) {
139 *didChangeAlloc = alloc;
140 }
141 if (alloc) {
142 if (fPtr != (void*)fStorage) {
143 sk_free(fPtr);
144 }
145
146 if (size == kSize) {
147 SkASSERT(fPtr != fStorage); // otherwise we lied when setting didChangeAlloc.
148 fPtr = fStorage;
149 } else {
150 fPtr = sk_malloc_throw(size);
151 }
152
153 fSize = size;
154 }
155 SkASSERT(fSize >= size && fSize >= kSize);
156 SkASSERT((fPtr == fStorage) || fSize > kSize);
157 return fPtr;
158 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
static void * sk_malloc_throw(size_t size)
Definition: SkMalloc.h:67

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