Class: AutoC::Allocator

Inherits:
Object
  • Object
show all
Includes:
Entity, STD, Singleton
Defined in:
lib/autoc/allocators.rb

Overview

Standard C malloc()-based dynamic memory handler

Constant Summary

Constants included from Entity

Entity::ReferenceSet

Constants included from STD

STD::ASSERT_H, STD::BOOL, STD::CHAR, STD::COMPLEX, STD::COMPLEX_H, STD::DOUBLE, STD::DOUBLE_COMPLEX, STD::DOUBLE_T, STD::FLOAT, STD::FLOAT_COMPLEX, STD::FLOAT_T, STD::INT, STD::INTMAX_T, STD::INTPTR_T, STD::INTTYPES_H, STD::LONG, STD::LONG_DOUBLE, STD::LONG_DOUBLE_COMPLEX, STD::LONG_LONG, STD::MALLOC_H, STD::MATH_H, STD::PTRDIFF_T, STD::SHORT, STD::SIGNED_CHAR, STD::SIZE_T, STD::STDBOOL_H, STD::STDDEF_H, STD::STDLIB_H, STD::STRING_H, STD::UINTMAX_T, STD::UINTPTR_T, STD::UNSIGNED, STD::UNSIGNED_CHAR, STD::UNSIGNED_LONG, STD::UNSIGNED_LONG_LONG, STD::UNSIGNED_SHORT, STD::WCHAR_T

Instance Method Summary collapse

Methods included from Entity

#<=>, #complexity, #dependencies, #forward_declarations, #implementation, #interface, #position, #references, #total_dependencies, #total_references

Constructor Details

#initializeAllocator

Returns a new instance of Allocator.



22
# File 'lib/autoc/allocators.rb', line 22

def initialize = dependencies << STDLIB_H

Instance Method Details

#allocate(type, count = 1, zero: false, **kws) ⇒ Object



24
25
26
# File 'lib/autoc/allocators.rb', line 24

def allocate(type, count = 1, zero: false, **kws)
  zero ? "(#{type}*)calloc(#{count}, sizeof(#{type}))" : "(#{type}*)malloc((#{count})*sizeof(#{type}))"
end

#free(pointer) ⇒ Object



28
# File 'lib/autoc/allocators.rb', line 28

def free(pointer) = "free(#{pointer})"