Module: Carbon::Core::Pointer::Memory Private
- Included in:
- Carbon::Core::Pointer
- Defined in:
- lib/carbon/core/pointer/memory.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Performs memory operations on a pointer. This is mainly alloc/free. C library functions are included in another module. This defines the following functions on the pointer type:
.alloc<T: Carbon::Numeric>(size: T): self.free(self): Carbon::Void
These are defined for every integer except boolean.
Instance Method Summary collapse
-
#define_alloc_function(int) ⇒ void
private
Defines the
allocfunction with the given integer type as the parameter. -
#define_free_function ⇒ void
private
Defines the
freefunction. -
#define_memory_functions ⇒ void
private
Defines all of the memory functions relative to each integer type.
Instance Method Details
#define_alloc_function(int) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Defines the alloc function with the given integer type as the
parameter. The alloc function allocates a block of memory and
returns it as a pointer.
36 37 38 39 40 41 42 |
# File 'lib/carbon/core/pointer/memory.rb', line 36 def define_alloc_function(int) function_name = PTYPE.call(:alloc, [int.name]) Core.define(function: function_name) do |function| function[:return] = PTYPE define_alloc_definition(int, function[:definition]) end end |
#define_free_function ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Defines the free function. The free function frees the current
pointer.
48 49 50 51 52 53 54 |
# File 'lib/carbon/core/pointer/memory.rb', line 48 def define_free_function function_name = PTYPE.call(:free, [PTYPE]) Core.define(function: function_name) do |function| function[:return] = Carbon::Type("Carbon::Void") define_free_definition(function[:definition]) end end |
#define_memory_functions ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Defines all of the memory functions relative to each integer type.
21 22 23 24 25 26 27 28 |
# File 'lib/carbon/core/pointer/memory.rb', line 21 def define_memory_functions Ints.each do |int| next if int.size == 1 define_alloc_function(int) end define_free_function end |