note
	description: "[
		To easily manage allocation and release of allocated C memory, and
		to perform insertion of basic elements. Byte order is by default
		platform specific.
		Although memory allocation routines do not accept a zero sized pointer
		MANAGED_POINTER does by allocating in fact a 1 byte sized pointer for
		this particular case.
	]"
	library: "Free implementation of ELKS library"
	status: "See notice at end of class."
	legal: "See notice at end of class."
	date: "$Date: 2020-05-19 14:29:33 +0000 (Tue, 19 May 2020) $"
	revision: "$Revision: 104259 $"

class 
	MANAGED_POINTER

create 
	make,
	make_from_array,
	make_from_pointer,
	share_from_pointer,
	own_from_pointer

feature {NONE} -- Initialization

	default_create
			-- Process instances of classes with no creation clause.
			-- (Default: do nothing.)
			-- (from ANY)
		do
		end

	make (n: INTEGER_32)
			-- Allocate item with n bytes.
		require
			n_non_negative: n >= 0
		do
			increment_counter
			item := item.memory_calloc (n.max (1), 1)
			if item = default_pointer then
				(create {EXCEPTIONS}).raise ("No more memory")
			end
			count := n
			is_shared := False
		ensure
			item_set: item /= default_pointer
			count_set: count = n
			is_shared_set: not is_shared
		end

	make_from_array (data: ARRAY [NATURAL_8])
			-- Allocate item with data.count bytes and copy
			-- content of data into item.
		require
			data_not_void: data /= Void
		do
			increment_counter
			count := data.count
			item := item.memory_alloc (count.max (1))
			if item = default_pointer then
				(create {EXCEPTIONS}).raise ("No more memory")
			end
			put_array (data, 0)
			is_shared := False
		ensure
			item_set: item /= default_pointer
			count_set: count = data.count
			is_shared_set: not is_shared
		end

	make_from_pointer (a_ptr: POINTER; n: INTEGER_32)
			-- Copy a_count bytes from a_ptr into current.
		require
			a_ptr_not_null: a_ptr /= default_pointer
			n_non_negative: n >= 0
		do
			increment_counter
			item := item.memory_alloc (n.max (1))
			if item = default_pointer then
				(create {EXCEPTIONS}).raise ("No more memory")
			end;
			item.memory_copy (a_ptr, n)
			count := n
			is_shared := False
		ensure
			item_set: item /= default_pointer
			count_set: count = n
			is_shared_set: not is_shared
		end

	own_from_pointer (a_ptr: POINTER; n: INTEGER_32)
			-- Use directly a_ptr with count n to hold current data and free
			-- its associated C memory when Current is collected.
			-- It assumes that a_ptr was allocated using the C-malloc routine and thus
			-- will be freed by calling the C-free routine.
		require
			a_ptr_valid: a_ptr /= default_pointer
			n_non_negative: n >= 0
		do
			increment_counter
			item := a_ptr
			count := n
			is_shared := False
		ensure
			item_set: item = a_ptr
			count_set: count = n
			is_shared_set: not is_shared
		end

	share_from_pointer (a_ptr: POINTER; n: INTEGER_32)
			-- Use directly a_ptr with count n to hold current data.
		require
			a_ptr_valid: a_ptr = default_pointer implies n = 0
			n_non_negative: n >= 0
		do
			increment_counter
			item := a_ptr
			count := n
			is_shared := True
		ensure
			item_set: item = a_ptr
			count_set: count = n
			is_shared_set: is_shared
		end
	
feature -- Access

	count: INTEGER_32
			-- Number of elements that Current can hold.

	generating_type: TYPE [detachable MANAGED_POINTER]
			-- Type of current object
			-- (type of which it is a direct instance)
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			generating_type_not_void: Result /= Void
		end

	generator: STRING_8
			-- Name of current object's generating class
			-- (base class of the type of which it is a direct instance)
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			generator_not_void: Result /= Void
			generator_not_empty: not Result.is_empty
		end

	is_shared: BOOLEAN
			-- Is item shared with another memory area?

	item: POINTER
		note
			option: transient
		attribute
		end
	
feature -- Comparison

	frozen deep_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void
			-- or attached to isomorphic object structures?
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.is_deep_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			shallow_implies_deep: standard_equal (a, b) implies Result
			both_or_none_void: (a = Void) implies (Result = (b = Void))
			same_type: (Result and (a /= Void)) implies (b /= Void and then a.same_type (b))
			symmetric: Result implies deep_equal (b, a)
		end

	frozen equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached
			-- to objects considered equal?
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.is_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.is_equal (b))
		end

	frozen is_deep_equal alias "≡≡≡" (other: MANAGED_POINTER): BOOLEAN
			-- Are Current and other attached to isomorphic object structures?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			shallow_implies_deep: standard_is_equal (other) implies Result
			same_type: Result implies same_type (other)
			symmetric: Result implies other.is_deep_equal (Current)
		end

	is_equal (other: like Current): BOOLEAN
			-- Is other attached to an object considered equal to current object?
		require -- from ANY
			other_not_void: other /= Void
		do
			if count = other.count then
				Result := (item = other.item) or else item.memory_compare (other.item, count)
			end
		ensure -- from ANY
			symmetric: Result implies other ~ Current
			consistent: standard_is_equal (other) implies Result
		end

	frozen standard_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached to
			-- field-by-field identical objects of the same type?
			-- Always uses default object comparison criterion.
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.standard_is_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.standard_is_equal (b))
		end

	frozen standard_is_equal alias "" (other: MANAGED_POINTER): BOOLEAN
			-- Is other attached to an object of the same type
			-- as current object, and field-by-field identical to it?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			same_type: Result implies same_type (other)
			symmetric: Result implies other.standard_is_equal (Current)
		end
	
feature {NONE} -- Status report

	is_in_final_collect: BOOLEAN
			-- Is GC currently performing final collection
			-- after execution of current program?
			-- Safe to use in dispose.
			-- (from DISPOSABLE)
		external
			"C inline use %"eif_memory.h%""
		alias
			"return eif_is_in_final_collect;"
		end
	
feature -- Status report

	conforms_to (other: ANY): BOOLEAN
			-- Does type of current object conform to type
			-- of other (as per Eiffel: The Language, chapter 13)?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		end

	same_type (other: ANY): BOOLEAN
			-- Is type of current object identical to type of other?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			definition: Result = (conforms_to (other) and other.conforms_to (Current))
		end
	
feature -- Resizing

	resize (n: INTEGER_32)
			-- Reallocate item to hold n bytes.
		require
			n_non_negative: n >= 0
			not_shared: not is_shared
		do
			if n /= count then
				item := item.memory_realloc (n.max (1))
				if item = default_pointer then
					(create {EXCEPTIONS}).raise ("No more memory")
				end
			end
			if n > count then
				(item + count).memory_set (0, n - count)
			end
			count := n
		end
	
feature -- Duplication

	frozen clone (other: detachable ANY): like other
		obsolete "Use `twin' instead. [2017-05-31]"
			-- Void if other is void; otherwise new object
			-- equal to other
			--
			-- For non-void other, clone calls copy;
			-- to change copying/cloning semantics, redefine copy.
			-- (from ANY)
		do
			if other /= Void then
				Result := other.twin
			end
		ensure -- from ANY
			instance_free: class
			equal: Result ~ other
		end

	copy (other: like Current)
			-- Update current object using fields of object attached
			-- to other, so as to yield equal objects. If is_shared
			-- and current is not large enough to hold other create
			-- a new pointer area and is_shared is set to False.
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		do
			if other /= Current then
				if item = other.item or is_shared then
					make_from_pointer (other.item, other.count)
				else
					resize (other.count);
					item.memory_copy (other.item, other.count)
				end
			end
		ensure -- from ANY
			is_equal: Current ~ other
		ensure then
			sharing_status_not_preserved: (other /= Current) implies (old is_shared implies not is_shared)
			count_preserved: count = other.count
		end

	frozen deep_clone (other: detachable ANY): like other
		obsolete "Use `deep_twin' instead. [2017-05-31]"
			-- Void if other is void: otherwise, new object structure
			-- recursively duplicated from the one attached to other
			-- (from ANY)
		do
			if other /= Void then
				Result := other.deep_twin
			end
		ensure -- from ANY
			instance_free: class
			deep_equal: deep_equal (other, Result)
		end

	frozen deep_copy (other: MANAGED_POINTER)
			-- Effect equivalent to that of:
			--		copy (other . deep_twin)
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		do
			copy (other.deep_twin)
		ensure -- from ANY
			deep_equal: deep_equal (Current, other)
		end

	frozen deep_twin: MANAGED_POINTER
			-- New object structure recursively duplicated from Current.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			deep_twin_not_void: Result /= Void
			deep_equal: deep_equal (Current, Result)
		end

	frozen standard_clone (other: detachable ANY): like other
		obsolete "Use `standard_twin' instead. [2017-05-31]"
			-- Void if other is void; otherwise new object
			-- field-by-field identical to other.
			-- Always uses default copying semantics.
			-- (from ANY)
		do
			if other /= Void then
				Result := other.standard_twin
			end
		ensure -- from ANY
			instance_free: class
			equal: standard_equal (Result, other)
		end

	frozen standard_copy (other: MANAGED_POINTER)
			-- Copy every field of other onto corresponding field
			-- of current object.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		external
			"built_in"
		ensure -- from ANY
			is_standard_equal: standard_is_equal (other)
		end

	frozen standard_twin: MANAGED_POINTER
			-- New object field-by-field identical to other.
			-- Always uses default copying semantics.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			standard_twin_not_void: Result /= Void
			equal: standard_equal (Result, Current)
		end

	frozen twin: MANAGED_POINTER
			-- New object equal to Current
			-- twin calls copy; to change copying/twinning semantics, redefine copy.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			twin_not_void: Result /= Void
			is_equal: Result ~ Current
		end
	
feature -- Basic operations

	frozen as_attached: attached MANAGED_POINTER
		obsolete "Remove calls to this feature. [2017-05-31]"
			-- Attached version of Current.
			-- (Can be used during transitional period to convert
			-- non-void-safe classes to void-safe ones.)
			-- (from ANY)
		do
			Result := Current
		end

	frozen default: detachable MANAGED_POINTER
			-- Default value of object's type
			-- (from ANY)
		do
		end

	frozen default_pointer: POINTER
			-- Default value of type POINTER
			-- (Avoid the need to write p.default for
			-- some p of type POINTER.)
			-- (from ANY)
		do
		ensure -- from ANY
			instance_free: class
		end

	default_rescue
			-- Process exception for routines with no Rescue clause.
			-- (Default: do nothing.)
			-- (from ANY)
		do
		end

	frozen do_nothing
			-- Execute a null action.
			-- (from ANY)
		do
		ensure -- from ANY
			instance_free: class
		end
	
feature -- Access bits size

	boolean_bits: INTEGER_32
			-- Number of bits in a value of type BOOLEAN
			-- (from PLATFORM)
		do
			Result := boolean_bytes * 8
		ensure -- from PLATFORM
			instance_free: class
		end

	Character_32_bits: INTEGER_32 = 32
			-- Number of bits in a value of type CHARACTER_32
			-- (from PLATFORM)

	Character_8_bits: INTEGER_32 = 8
			-- Number of bits in a value of type CHARACTER_8
			-- (from PLATFORM)

	Integer_16_bits: INTEGER_32 = 16
			-- Number of bits in a value of type INTEGER_16
			-- (from PLATFORM)

	Integer_32_bits: INTEGER_32 = 32
			-- Number of bits in a value of type INTEGER_32
			-- (from PLATFORM)

	Integer_64_bits: INTEGER_32 = 64
			-- Number of bits in a value of type INTEGER_64
			-- (from PLATFORM)

	Integer_8_bits: INTEGER_32 = 8
			-- Number of bits in a value of type INTEGER_8
			-- (from PLATFORM)

	Natural_16_bits: INTEGER_32 = 16
			-- Number of bits in a value of type NATURAL_16
			-- (from PLATFORM)

	Natural_32_bits: INTEGER_32 = 32
			-- Number of bits in a value of type NATURAL_32
			-- (from PLATFORM)

	Natural_64_bits: INTEGER_32 = 64
			-- Number of bits in a value of type NATURAL_64
			-- (from PLATFORM)

	Natural_8_bits: INTEGER_32 = 8
			-- Number of bits in a value of type NATURAL_8
			-- (from PLATFORM)

	pointer_bits: INTEGER_32
			-- Number of bits in a value of type POINTER
			-- (from PLATFORM)
		do
			Result := pointer_bytes * 8
		ensure -- from PLATFORM
			instance_free: class
		end

	Real_32_bits: INTEGER_32 = 32
			-- Number of bits in a value of type REAL_32
			-- (from PLATFORM)

	Real_64_bits: INTEGER_32 = 64
			-- Number of bits in a value of type REAL_64
			-- (from PLATFORM)
	
feature -- Access bytes size

	boolean_bytes: INTEGER_32
			-- Number of bytes in a value of type BOOLEAN
			-- (from PLATFORM)
		external
			"built_in static"
		ensure -- from PLATFORM
			instance_free: class
		end

	Character_32_bytes: INTEGER_32 = 4
			-- Number of bytes in a value of type CHARACTER_32
			-- (from PLATFORM)

	Character_8_bytes: INTEGER_32 = 1
			-- Number of bytes in a value of type CHARACTER_8
			-- (from PLATFORM)

	Integer_16_bytes: INTEGER_32 = 2
			-- Number of bytes in a value of type INTEGER_16
			-- (from PLATFORM)

	Integer_32_bytes: INTEGER_32 = 4
			-- Number of bytes in a value of type INTEGER_32
			-- (from PLATFORM)

	Integer_64_bytes: INTEGER_32 = 8
			-- Number of bytes in a value of type INTEGER_64
			-- (from PLATFORM)

	Integer_8_bytes: INTEGER_32 = 1
			-- Number of bytes in a value of type INTEGER_8
			-- (from PLATFORM)

	Natural_16_bytes: INTEGER_32 = 2
			-- Number of bytes in a value of type NATURAL_16
			-- (from PLATFORM)

	Natural_32_bytes: INTEGER_32 = 4
			-- Number of bytes in a value of type NATURAL_32
			-- (from PLATFORM)

	Natural_64_bytes: INTEGER_32 = 8
			-- Number of bytes in a value of type NATURAL_64
			-- (from PLATFORM)

	Natural_8_bytes: INTEGER_32 = 1
			-- Number of bytes in a value of type NATURAL_8
			-- (from PLATFORM)

	pointer_bytes: INTEGER_32
			-- Number of bytes in a value of type POINTER
			-- (from PLATFORM)
		external
			"built_in static"
		ensure -- from PLATFORM
			instance_free: class
		end

	Real_32_bytes: INTEGER_32 = 4
			-- Number of bytes in a value of type REAL_32
			-- (from PLATFORM)

	Real_64_bytes: INTEGER_32 = 8
			-- Number of bytes in a value of type REAL_64
			-- (from PLATFORM)
	
feature -- Access: Big-endian format

	read_integer_16_be (pos: INTEGER_32): INTEGER_16
			-- Read INTEGER_16 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_16_bytes) <= count
		do
			Result := read_natural_16_be (pos).as_integer_16
		end

	read_integer_32_be (pos: INTEGER_32): INTEGER_32
			-- Read INTEGER at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_32_bytes) <= count
		do
			Result := read_natural_32_be (pos).as_integer_32
		end

	read_integer_64_be (pos: INTEGER_32): INTEGER_64
			-- Read INTEGER_64 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_64_bytes) <= count
		do
			Result := read_natural_64_be (pos).as_integer_64
		end

	read_integer_8_be (pos: INTEGER_32): INTEGER_8
			-- Read INTEGER_8 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_8_bytes) <= count
		do
			Result := read_natural_8_be (pos).as_integer_8
		end

	read_natural_16_be (pos: INTEGER_32): NATURAL_16
			-- Read NATURAL_16 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_16_bytes) <= count
		local
			l_high, l_low: NATURAL_16
		do
			if Is_little_endian then
				l_high := read_natural_8 (pos).to_natural_16
				l_low := (255).to_natural_16 & read_natural_8 (pos + Natural_8_bytes).to_natural_16
				Result := (l_high.to_natural_16 |<< 8) | l_low
			else
				Result := read_natural_16 (pos)
			end
		end

	read_natural_32_be (pos: INTEGER_32): NATURAL_32
			-- Read NATURAL_32 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_32_bytes) <= count
		local
			l_high, l_low: NATURAL_32
		do
			if Is_little_endian then
				l_high := read_natural_16_be (pos).to_natural_32
				l_low := (65535).to_natural_32 & read_natural_16_be (pos + Natural_16_bytes).to_natural_32
				Result := (l_high.to_natural_32 |<< 16) | l_low
			else
				Result := read_natural_32 (pos)
			end
		end

	read_natural_64_be (pos: INTEGER_32): NATURAL_64
			-- Read NATURAL_64 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_64_bytes) <= count
		local
			l_high, l_low: NATURAL_64
		do
			if Is_little_endian then
				l_high := read_natural_32_be (pos).to_natural_64
				l_low := {NATURAL_64} 4294967295 & read_natural_32_be (pos + Natural_32_bytes).to_natural_64
				Result := (l_high.to_natural_64 |<< 32) | l_low
			else
				Result := read_natural_64 (pos)
			end
		end

	read_natural_8_be (pos: INTEGER_32): NATURAL_8
			-- Read NATURAL_8 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_8_bytes) <= count
		do
			($Result).memory_copy (item + pos, Natural_8_bytes)
		end

	read_real_32_be (pos: INTEGER_32): REAL_32
			-- Read REAL_32 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Real_32_bytes) <= count
		local
			l_nat32: NATURAL_32
		do
			check
				correct_size: Real_32_bytes = Natural_32_bytes
			end
			l_nat32 := read_natural_32_be (pos);
			($Result).memory_copy ($l_nat32.to_pointer, Natural_32_bytes)
		end

	read_real_64_be (pos: INTEGER_32): REAL_64
			-- Read REAL_64 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Real_64_bytes) <= count
		local
			l_nat64: NATURAL_64
		do
			check
				correct_size: Real_64_bytes = Natural_64_bytes
			end
			l_nat64 := read_natural_64_be (pos);
			($Result).memory_copy ($l_nat64.to_pointer, Natural_64_bytes)
		end
	
feature -- Access: Little-endian format

	read_integer_16_le (pos: INTEGER_32): INTEGER_16
			-- Read INTEGER_16 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_16_bytes) <= count
		do
			Result := read_natural_16_le (pos).as_integer_16
		end

	read_integer_32_le (pos: INTEGER_32): INTEGER_32
			-- Read INTEGER at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_32_bytes) <= count
		do
			Result := read_natural_32_le (pos).as_integer_32
		end

	read_integer_64_le (pos: INTEGER_32): INTEGER_64
			-- Read INTEGER_64 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_64_bytes) <= count
		do
			Result := read_natural_64_le (pos).as_integer_64
		end

	read_integer_8_le (pos: INTEGER_32): INTEGER_8
			-- Read INTEGER_8 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_8_bytes) <= count
		do
			Result := read_natural_8_le (pos).as_integer_8
		end

	read_natural_16_le (pos: INTEGER_32): NATURAL_16
			-- Read NATURAL_16 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_16_bytes) <= count
		local
			l_low: NATURAL_16
		do
			if Is_little_endian then
				Result := read_natural_16 (pos)
			else
				l_low := {NATURAL_16} 255 & read_natural_8 (pos).to_natural_16
				Result := (read_natural_8 (pos + Natural_8_bytes).to_natural_16 |<< 8) | l_low
			end
		end

	read_natural_32_le (pos: INTEGER_32): NATURAL_32
			-- Read NATURAL_32 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_32_bytes) <= count
		local
			l_high, l_low: NATURAL_32
		do
			if Is_little_endian then
				Result := read_natural_32 (pos)
			else
				l_low := {NATURAL_32} 65535 & read_natural_16_le (pos).to_natural_32
				l_high := read_natural_16_le (pos + Natural_16_bytes).to_natural_32
				Result := (l_high.to_natural_32 |<< 16) | l_low
			end
		end

	read_natural_64_le (pos: INTEGER_32): NATURAL_64
			-- Read NATURAL_64 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_64_bytes) <= count
		local
			l_high, l_low: NATURAL_64
		do
			if Is_little_endian then
				Result := read_natural_64 (pos)
			else
				l_low := {NATURAL_64} 4294967295 & read_natural_32_le (pos).to_natural_64
				l_high := read_natural_32_le (pos + Natural_32_bytes).to_natural_64
				Result := (l_high.to_natural_64 |<< 32) | l_low
			end
		end

	read_natural_8_le (pos: INTEGER_32): NATURAL_8
			-- Read NATURAL_8 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_8_bytes) <= count
		do
			($Result).memory_copy (item + pos, Natural_8_bytes)
		end

	read_real_32_le (pos: INTEGER_32): REAL_32
			-- Read REAL_32 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Real_32_bytes) <= count
		local
			l_nat32: NATURAL_32
		do
			check
				correct_size: Real_32_bytes = Natural_32_bytes
			end
			l_nat32 := read_natural_32_le (pos);
			($Result).memory_copy ($l_nat32.to_pointer, Natural_32_bytes)
		end

	read_real_64_le (pos: INTEGER_32): REAL_64
			-- Read REAL_64 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Real_64_bytes) <= count
		local
			l_nat64: NATURAL_64
		do
			check
				correct_size: Real_64_bytes = Natural_64_bytes
			end
			l_nat64 := read_natural_64_le (pos);
			($Result).memory_copy ($l_nat64.to_pointer, Natural_64_bytes)
		end
	
feature -- Access: Platform specific

	read_array (pos, a_count: INTEGER_32): ARRAY [NATURAL_8]
			-- Read count bytes at position pos.
		require
			pos_nonnegative: pos >= 0
			count_positive: a_count > 0
			valid_position: (pos + a_count) <= count
		local
			l_area: SPECIAL [NATURAL_8]
		do
			create l_area.make_filled (0, a_count)
			read_into_special_natural_8 (l_area, pos, 0, a_count)
			create Result.make_from_special (l_area)
		ensure
			read_array_not_void: Result /= Void
			read_array_valid_count: Result.count = a_count
		end

	read_boolean (pos: INTEGER_32): BOOLEAN
			-- Read BOOLEAN at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + boolean_bytes) <= count
		do
			($Result).memory_copy (item + pos, boolean_bytes)
		end

	read_character (pos: INTEGER_32): CHARACTER_8
			-- Read CHARACTER at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Character_8_bytes) <= count
		do
			($Result).memory_copy (item + pos, Character_8_bytes)
		end

	read_double (pos: INTEGER_32): REAL_64
		obsolete "Use read_real_64 instead. [2017-05-31]"
			-- Read REAL_64 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Real_64_bytes) <= count
		do
			($Result).memory_copy (item + pos, Real_64_bytes)
		end

	read_integer_16 (pos: INTEGER_32): INTEGER_16
			-- Read INTEGER_16 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_16_bytes) <= count
		do
			Result := read_natural_16 (pos).as_integer_16
		end

	read_integer_32 (pos: INTEGER_32): INTEGER_32
			-- Read INTEGER at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_32_bytes) <= count
		do
			Result := read_natural_32 (pos).as_integer_32
		end

	read_integer_64 (pos: INTEGER_32): INTEGER_64
			-- Read INTEGER_64 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_64_bytes) <= count
		do
			Result := read_natural_64 (pos).as_integer_64
		end

	read_integer_8 (pos: INTEGER_32): INTEGER_8
			-- Read INTEGER_8 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_8_bytes) <= count
		do
			Result := read_natural_8 (pos).as_integer_8
		end

	read_into_special_character_8 (a_spec: SPECIAL [CHARACTER_8]; source_index, destination_index, n: INTEGER_32)
			-- Read n bytes of Current from position source_index and store them in a_spec at destination_index.
		require
			a_spec_not_void: a_spec /= Void
			source_index_non_negative: source_index >= 0
			destination_index_non_negative: destination_index >= 0
			destination_index_in_bound: destination_index <= a_spec.count
			n_non_negative: n >= 0
			n_is_small_enough_for_source: source_index + n <= count
			n_is_small_enough_for_destination: destination_index + n <= a_spec.count
		do
			a_spec.item_address (destination_index).memory_copy (item + source_index, n)
		end

	read_into_special_natural_8 (a_spec: SPECIAL [NATURAL_8]; source_index, destination_index, n: INTEGER_32)
			-- Read n bytes of Current from position source_index and store them in a_spec at destination_index.
		require
			a_spec_not_void: a_spec /= Void
			source_index_non_negative: source_index >= 0
			destination_index_non_negative: destination_index >= 0
			destination_index_in_bound: destination_index <= a_spec.count
			n_non_negative: n >= 0
			n_is_small_enough_for_source: source_index + n <= count
			n_is_small_enough_for_destination: destination_index + n <= a_spec.count
		do
			a_spec.item_address (destination_index).memory_copy (item + source_index, n)
		end

	read_natural_16 (pos: INTEGER_32): NATURAL_16
			-- Read NATURAL_16 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_16_bytes) <= count
		do
			($Result).memory_copy (item + pos, Natural_16_bytes)
		end

	read_natural_32 (pos: INTEGER_32): NATURAL_32
			-- Read NATURAL_32 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_32_bytes) <= count
		do
			($Result).memory_copy (item + pos, Natural_32_bytes)
		end

	read_natural_64 (pos: INTEGER_32): NATURAL_64
			-- Read NATURAL_64 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_64_bytes) <= count
		do
			($Result).memory_copy (item + pos, Natural_64_bytes)
		end

	read_natural_8 (pos: INTEGER_32): NATURAL_8
			-- Read NATURAL_8 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_8_bytes) <= count
		do
			($Result).memory_copy (item + pos, Natural_8_bytes)
		end

	read_pointer (pos: INTEGER_32): POINTER
			-- Read POINTER at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + pointer_bytes) <= count
		do
			($Result).memory_copy (item + pos, pointer_bytes)
		end

	read_real (pos: INTEGER_32): REAL_32
		obsolete "Use read_real_32 instead. [2017-05-31]"
			-- Read REAL_32 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Real_32_bytes) <= count
		do
			($Result).memory_copy (item + pos, Real_32_bytes)
		end

	read_real_32 (pos: INTEGER_32): REAL_32
			-- Read REAL_32 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Real_32_bytes) <= count
		do
			($Result).memory_copy (item + pos, Real_32_bytes)
		end

	read_real_64 (pos: INTEGER_32): REAL_64
			-- Read REAL_64 at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Real_64_bytes) <= count
		do
			($Result).memory_copy (item + pos, Real_64_bytes)
		end

	read_special_character_8 (source_index, n: INTEGER_32): SPECIAL [CHARACTER_8]
			-- Read n bytes of Current from position source_index.
		require
			source_index_non_negative: source_index >= 0
			n_non_negative: n >= 0
			n_is_small_enough_for_source: source_index + n <= count
		do
			create Result.make_filled ('%U', n)
			read_into_special_character_8 (Result, source_index, 0, n)
		end

	read_special_natural_8 (source_index, n: INTEGER_32): SPECIAL [NATURAL_8]
			-- Read n bytes of Current from position source_index.
		require
			source_index_non_negative: source_index >= 0
			n_non_negative: n >= 0
			n_is_small_enough_for_source: source_index + n <= count
		do
			create Result.make_filled (0, n)
			read_into_special_natural_8 (Result, source_index, 0, n)
		end
	
feature -- Concatenation

	append (other: like Current)
			-- Append other at the end of Current.
		require
			not_shared: not is_shared
			other_not_void: other /= Void
		local
			new_count: INTEGER_32
		do
			new_count := count + other.count
			item := item.memory_realloc (new_count.max (1))
			if item = default_pointer then
				(create {EXCEPTIONS}).raise ("No more memory")
			end;
			(item + count).memory_copy (other.item, other.count)
			count := new_count
		end
	
feature {NONE} -- Debugging

	Allocation_counter: CELL [NATURAL_64]
			-- Store current number of allocation being made.
		once
			create Result.put (0)
		end

	counter: NATURAL_64
		note
			option: transient
		attribute
		end

	increment_counter
			-- Set counter with a new allocation number.
		do
			debug ("managed_pointer_allocation")
				counter := Allocation_counter.item + 1;
				Allocation_counter.put (counter)
			end
		end
	
feature -- Disposal

	dispose
			-- Release memory pointed by item.
		require -- from  DISPOSABLE
			True
		local
			null: POINTER
		do
			if not is_shared then
				item.memory_free
			end
			item := null
			is_shared := False
		ensure then
			shared_reset: not is_shared
		end
	
feature -- Element change: Big-endian format

	put_integer_16_be (i: INTEGER_16; pos: INTEGER_32)
			-- Insert i at position pos in big-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_16_bytes) <= count
		do
			put_natural_16_be (i.as_natural_16, pos)
		ensure
			inserted: i = read_integer_16_be (pos)
		end

	put_integer_32_be (i: INTEGER_32; pos: INTEGER_32)
			-- Insert i at position pos in big-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_32_bytes) <= count
		do
			put_natural_32_be (i.as_natural_32, pos)
		ensure
			inserted: i = read_integer_32_be (pos)
		end

	put_integer_64_be (i: INTEGER_64; pos: INTEGER_32)
			-- Insert i at position pos in big-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_64_bytes) <= count
		do
			put_natural_64_be (i.as_natural_64, pos)
		ensure
			inserted: i = read_integer_64_be (pos)
		end

	put_integer_8_be (i: INTEGER_8; pos: INTEGER_32)
			-- Insert i at position pos in big-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_8_bytes) <= count
		do
			put_natural_8_be (i.as_natural_8, pos)
		ensure
			inserted: i = read_integer_8_be (pos)
		end

	put_natural_16_be (i: NATURAL_16; pos: INTEGER_32)
			-- Insert i at position pos in big-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_16_bytes) <= count
		do
			if Is_little_endian then
				put_natural_8 ((((i & 65280) |>> 8) & 255).to_natural_8, pos)
				put_natural_8 ((i & 255).to_natural_8, pos + Natural_8_bytes)
			else
				put_natural_16 (i, pos)
			end
		ensure
			inserted: i = read_natural_16_be (pos)
		end

	put_natural_32_be (i: NATURAL_32; pos: INTEGER_32)
			-- Insert i at position pos in big-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_32_bytes) <= count
		do
			if Is_little_endian then
				put_natural_16_be ((((i & 4294901760) |>> 16) & 65535).to_natural_16, pos)
				put_natural_16_be ((i & 65535).to_natural_16, pos + Natural_16_bytes)
			else
				put_natural_32 (i, pos)
			end
		ensure
			inserted: i = read_natural_32_be (pos)
		end

	put_natural_64_be (i: NATURAL_64; pos: INTEGER_32)
			-- Insert i at position pos in big-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_64_bytes) <= count
		do
			if Is_little_endian then
				put_natural_32_be ((((i & 18446744069414584320) |>> 32) & 4294967295).to_natural_32, pos)
				put_natural_32_be ((i & 4294967295).to_natural_32, pos + Natural_32_bytes)
			else
				put_natural_64 (i, pos)
			end
		ensure
			inserted: i = read_natural_64_be (pos)
		end

	put_natural_8_be (i: NATURAL_8; pos: INTEGER_32)
			-- Insert i at position pos in big-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_8_bytes) <= count
		do
			(item + pos).memory_copy ($i.to_pointer, Natural_8_bytes)
		ensure
			inserted: i = read_natural_8_be (pos)
		end

	put_real_32_be (v: REAL_32; pos: INTEGER_32)
			-- Insert v at position pos in big-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Real_32_bytes) <= count
		local
			l_nat32: NATURAL_32
		do
			check
				correct_size: Real_32_bytes = Natural_32_bytes
			end;
			($l_nat32).memory_copy ($v.to_pointer, Natural_32_bytes)
			put_natural_32_be (l_nat32, pos)
		ensure
			inserted: v = read_real_32_be (pos)
		end

	put_real_64_be (v: REAL_64; pos: INTEGER_32)
			-- Insert v at position pos in big-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Real_64_bytes) <= count
		local
			l_nat64: NATURAL_64
		do
			check
				correct_size: Real_64_bytes = Natural_64_bytes
			end;
			($l_nat64).memory_copy ($v.to_pointer, Natural_64_bytes)
			put_natural_64_be (l_nat64, pos)
		ensure
			inserted: v = read_real_64_be (pos)
		end
	
feature -- Element change: Little-endian format

	put_integer_16_le (i: INTEGER_16; pos: INTEGER_32)
			-- Insert i at position pos in little-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_16_bytes) <= count
		do
			put_natural_16_le (i.as_natural_16, pos)
		ensure
			inserted: i = read_integer_16_le (pos)
		end

	put_integer_32_le (i: INTEGER_32; pos: INTEGER_32)
			-- Insert i at position pos in little-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_32_bytes) <= count
		do
			put_natural_32_le (i.as_natural_32, pos)
		ensure
			inserted: i = read_integer_32_le (pos)
		end

	put_integer_64_le (i: INTEGER_64; pos: INTEGER_32)
			-- Insert i at position pos in little-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_64_bytes) <= count
		do
			put_natural_64_le (i.as_natural_64, pos)
		ensure
			inserted: i = read_integer_64_le (pos)
		end

	put_integer_8_le (i: INTEGER_8; pos: INTEGER_32)
			-- Insert i at position pos in little-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_8_bytes) <= count
		do
			put_natural_8_le (i.as_natural_8, pos)
		ensure
			inserted: i = read_integer_8_le (pos)
		end

	put_natural_16_le (i: NATURAL_16; pos: INTEGER_32)
			-- Insert i at position pos in little-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_16_bytes) <= count
		do
			if Is_little_endian then
				put_natural_16 (i, pos)
			else
				put_natural_8 ((i & 255).to_natural_8, pos)
				put_natural_8 ((((i & 65280) |>> 8) & 255).to_natural_8, pos + Natural_8_bytes)
			end
		ensure
			inserted: i = read_natural_16_le (pos)
		end

	put_natural_32_le (i: NATURAL_32; pos: INTEGER_32)
			-- Insert i at position pos in little-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_32_bytes) <= count
		do
			if Is_little_endian then
				put_natural_32 (i, pos)
			else
				put_natural_16_le ((i & 65535).to_natural_16, pos)
				put_natural_16_le ((((i & 4294901760) |>> 16) & 65535).to_natural_16, pos + Natural_16_bytes)
			end
		ensure
			inserted: i = read_natural_32_le (pos)
		end

	put_natural_64_le (i: NATURAL_64; pos: INTEGER_32)
			-- Insert i at position pos in little-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_64_bytes) <= count
		do
			if Is_little_endian then
				put_natural_64 (i, pos)
			else
				put_natural_32_le ((i & 4294967295).to_natural_32, pos)
				put_natural_32_le ((((i & 18446744069414584320) |>> 32) & 4294967295).to_natural_32, pos + Natural_32_bytes)
			end
		ensure
			inserted: i = read_natural_64_le (pos)
		end

	put_natural_8_le (i: NATURAL_8; pos: INTEGER_32)
			-- Insert i at position pos in little-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_8_bytes) <= count
		do
			(item + pos).memory_copy ($i.to_pointer, Natural_8_bytes)
		ensure
			inserted: i = read_natural_8_le (pos)
		end

	put_real_32_le (v: REAL_32; pos: INTEGER_32)
			-- Insert v at position pos in little-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Real_32_bytes) <= count
		local
			l_nat32: NATURAL_32
		do
			check
				correct_size: Real_32_bytes = Natural_32_bytes
			end;
			($l_nat32).memory_copy ($v.to_pointer, Natural_32_bytes)
			put_natural_32_le (l_nat32, pos)
		ensure
			inserted: v = read_real_32_le (pos)
		end

	put_real_64_le (v: REAL_64; pos: INTEGER_32)
			-- Insert v at position pos in little-endian format.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Real_64_bytes) <= count
		local
			l_nat64: NATURAL_64
		do
			check
				correct_size: Real_64_bytes = Natural_64_bytes
			end;
			($l_nat64).memory_copy ($v.to_pointer, Natural_64_bytes)
			put_natural_64_le (l_nat64, pos)
		ensure
			inserted: v = read_real_64_le (pos)
		end
	
feature -- Element change: Platform specific

	put_array (data: ARRAY [NATURAL_8]; pos: INTEGER_32)
			-- Copy content of data into item at position pos.
		require
			data_not_void: data /= Void
			pos_nonnegative: pos >= 0
			valid_position: (pos + data.count) <= count
		local
			l_sp: SPECIAL [NATURAL_8]
		do
			l_sp := data.area;
			(item + pos).memory_copy ($l_sp.to_pointer, data.count)
		ensure
			inserted: read_array (pos, data.count) ~ data
		end

	put_boolean (b: BOOLEAN; pos: INTEGER_32)
			-- Insert b at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + boolean_bytes) <= count
		do
			(item + pos).memory_copy ($b.to_pointer, boolean_bytes)
		ensure
			inserted: b = read_boolean (pos)
		end

	put_character (c: CHARACTER_8; pos: INTEGER_32)
			-- Insert c at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Character_8_bytes) <= count
		do
			(item + pos).memory_copy ($c.to_pointer, Character_8_bytes)
		ensure
			inserted: c = read_character (pos)
		end

	put_double (d: REAL_64; pos: INTEGER_32)
		obsolete "Use put_real_64 instead. [2017-05-31]"
			-- Insert d at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Real_64_bytes) <= count
		do
			(item + pos).memory_copy ($d.to_pointer, Real_64_bytes)
		ensure
			inserted: d = read_real_64 (pos)
		end

	put_integer_16 (i: INTEGER_16; pos: INTEGER_32)
			-- Insert i at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_16_bytes) <= count
		do
			put_natural_16 (i.as_natural_16, pos)
		ensure
			inserted: i = read_integer_16 (pos)
		end

	put_integer_32 (i: INTEGER_32; pos: INTEGER_32)
			-- Insert i at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_32_bytes) <= count
		do
			put_natural_32 (i.as_natural_32, pos)
		ensure
			inserted: i = read_integer_32 (pos)
		end

	put_integer_64 (i: INTEGER_64; pos: INTEGER_32)
			-- Insert i at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_64_bytes) <= count
		do
			put_natural_64 (i.as_natural_64, pos)
		ensure
			inserted: i = read_integer_64 (pos)
		end

	put_integer_8 (i: INTEGER_8; pos: INTEGER_32)
			-- Insert i at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Integer_8_bytes) <= count
		do
			put_natural_8 (i.as_natural_8, pos)
		ensure
			inserted: i = read_integer_8 (pos)
		end

	put_natural_16 (i: NATURAL_16; pos: INTEGER_32)
			-- Insert i at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_16_bytes) <= count
		do
			(item + pos).memory_copy ($i.to_pointer, Natural_16_bytes)
		ensure
			inserted: i = read_natural_16 (pos)
		end

	put_natural_32 (i: NATURAL_32; pos: INTEGER_32)
			-- Insert i at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_32_bytes) <= count
		do
			(item + pos).memory_copy ($i.to_pointer, Natural_32_bytes)
		ensure
			inserted: i = read_natural_32 (pos)
		end

	put_natural_64 (i: NATURAL_64; pos: INTEGER_32)
			-- Insert i at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_64_bytes) <= count
		do
			(item + pos).memory_copy ($i.to_pointer, Natural_64_bytes)
		ensure
			inserted: i = read_natural_64 (pos)
		end

	put_natural_8 (i: NATURAL_8; pos: INTEGER_32)
			-- Insert i at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Natural_8_bytes) <= count
		do
			(item + pos).memory_copy ($i.to_pointer, Natural_8_bytes)
		ensure
			inserted: i = read_natural_8 (pos)
		end

	put_pointer (p: POINTER; pos: INTEGER_32)
			-- Insert p at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + pointer_bytes) <= count
		do
			(item + pos).memory_copy ($p.to_pointer, pointer_bytes)
		ensure
			inserted: p = read_pointer (pos)
		end

	put_real (r: REAL_32; pos: INTEGER_32)
		obsolete "Use put_real_32 instead. [2017-05-31]"
			-- Insert r at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Real_32_bytes) <= count
		do
			(item + pos).memory_copy ($r.to_pointer, Real_32_bytes)
		ensure
			inserted: r = read_real_32 (pos)
		end

	put_real_32 (r: REAL_32; pos: INTEGER_32)
			-- Insert r at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Real_32_bytes) <= count
		do
			(item + pos).memory_copy ($r.to_pointer, Real_32_bytes)
		ensure
			inserted: r = read_real_32 (pos)
		end

	put_real_64 (d: REAL_64; pos: INTEGER_32)
			-- Insert d at position pos.
		require
			pos_nonnegative: pos >= 0
			valid_position: (pos + Real_64_bytes) <= count
		do
			(item + pos).memory_copy ($d.to_pointer, Real_64_bytes)
		ensure
			inserted: d = read_real_64 (pos)
		end

	put_special_character_8 (a_spec: SPECIAL [CHARACTER_8]; source_index, destination_index, n: INTEGER_32)
			-- Write n bytes of a_spec from position source_index to Current at position destination_index.
		require
			a_spec_not_void: a_spec /= Void
			source_index_non_negative: source_index >= 0
			destination_index_non_negative: destination_index >= 0
			destination_index_in_bound: destination_index <= count
			n_non_negative: n >= 0
			n_is_small_enough_for_source: source_index + n <= a_spec.count
			n_is_small_enough_for_destination: destination_index + n <= count
		do
			(item + destination_index).memory_copy (a_spec.item_address (source_index), n)
		ensure
			inserted: a_spec.same_items (read_special_character_8 (destination_index, n), 0, source_index, n)
		end

	put_special_natural_8 (a_spec: SPECIAL [NATURAL_8]; source_index, destination_index, n: INTEGER_32)
			-- Write n bytes of a_spec from position source_index to Current at position destination_index.
		require
			a_spec_not_void: a_spec /= Void
			source_index_non_negative: source_index >= 0
			destination_index_non_negative: destination_index >= 0
			destination_index_in_bound: destination_index <= count
			n_non_negative: n >= 0
			n_is_small_enough_for_source: source_index + n <= a_spec.count
			n_is_small_enough_for_destination: destination_index + n <= count
		do
			(item + destination_index).memory_copy (a_spec.item_address (source_index), n)
		ensure
			inserted: a_spec.same_items (read_special_natural_8 (destination_index, n), 0, source_index, n)
		end
	
feature -- Obsoletes

	character_bits: INTEGER_32
		obsolete "Use `character_8_bits' instead. [2017-05-31]"
			-- Number of bits in a value of type CHARACTER_8
			-- (from PLATFORM)
		do
			Result := 8
		ensure -- from PLATFORM
			instance_free: class
		end

	character_bytes: INTEGER_32
		obsolete "Use `character_8_bytes' instead. [2017-05-31]"
			-- Number of bytes in a value of type CHARACTER_8
			-- (from PLATFORM)
		external
			"built_in static"
		ensure -- from PLATFORM
			instance_free: class
		end

	double_bits: INTEGER_32
		obsolete "Use `real_64_bits' instead. [2017-05-31]"
			-- Number of bits in a value of type REAL_64
			-- (from PLATFORM)
		do
			Result := 64
		ensure -- from PLATFORM
			instance_free: class
		end

	double_bytes: INTEGER_32
		obsolete "Use `real_64_bytes' instead. [2017-05-31]"
			-- Number of bytes in a value of type REAL_64
			-- (from PLATFORM)
		external
			"built_in static"
		ensure -- from PLATFORM
			instance_free: class
		end

	integer_bits: INTEGER_32
		obsolete "Use `integer_32_bits' instead. [2017-05-31]"
			-- Number of bits in a value of type INTEGER_32
			-- (from PLATFORM)
		do
			Result := 32
		ensure -- from PLATFORM
			instance_free: class
		end

	integer_bytes: INTEGER_32
		obsolete "Use `integer_32_bytes' instead. [2017-05-31]"
			-- Number of bytes in a value of type INTEGER_32
			-- (from PLATFORM)
		external
			"built_in static"
		ensure -- from PLATFORM
			instance_free: class
		end

	maximum_character_code: INTEGER_32
		obsolete "Use `{CHARACTER_8}.max_value' instead. [2017-05-31]"
			-- Largest supported code for CHARACTER_8 values
			-- (from PLATFORM)
		do
			Result := {CHARACTER_8}.max_value
		ensure -- from PLATFORM
			instance_free: class
			meaningful: Result >= 127
		end

	maximum_integer: INTEGER_32
		obsolete "Use `{INTEGER}.max_value' instead. [2017-05-31]"
			-- Largest supported value of type INTEGER_32
			-- (from PLATFORM)
		do
			Result := {INTEGER_32}.max_value
		ensure -- from PLATFORM
			instance_free: class
			meaningful: Result >= 0
		end

	minimum_character_code: INTEGER_32
		obsolete "Use `{CHARACTER_8}.min_value' instead. [2017-05-31]"
			-- Smallest supported code for CHARACTER_8 values
			-- (from PLATFORM)
		do
			Result := {CHARACTER_8}.min_value
		ensure -- from PLATFORM
			instance_free: class
			meaningful: Result <= 0
		end

	minimum_integer: INTEGER_32
		obsolete "Use `{INTEGER}.min_value' instead. [2017-05-31]"
			-- Smallest supported value of type INTEGER_32
			-- (from PLATFORM)
		do
			Result := {INTEGER_32}.min_value
		ensure -- from PLATFORM
			instance_free: class
			meaningful: Result <= 0
		end

	real_bits: INTEGER_32
		obsolete "Use `real_32_bits' instead. [2017-05-31]"
			-- Number of bits in a value of type REAL_32
			-- (from PLATFORM)
		do
			Result := 32
		ensure -- from PLATFORM
			instance_free: class
		end

	real_bytes: INTEGER_32
		obsolete "Use `real_32_bytes' instead. [2017-05-31]"
			-- Number of bytes in a value of type REAL_32
			-- (from PLATFORM)
		external
			"built_in static"
		ensure -- from PLATFORM
			instance_free: class
		end

	wide_character_bytes: INTEGER_32
		obsolete "Use `character_32_bytes' instead. [2017-05-31]"
			-- Number of bytes in a value of type CHARACTER_32
			-- (from PLATFORM)
		external
			"built_in static"
		ensure -- from PLATFORM
			instance_free: class
		end
	
feature -- Output

	Io: STD_FILES
			-- Handle to standard file setup
			-- (from ANY)
		once
			create Result;
			Result.set_output_default
		ensure -- from ANY
			instance_free: class
			io_not_void: Result /= Void
		end

	out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		do
			Result := tagged_out
		ensure -- from ANY
			out_not_void: Result /= Void
		end

	print (o: detachable ANY)
			-- Write terse external representation of o
			-- on standard output.
			-- (from ANY)
		local
			s: READABLE_STRING_8
		do
			if attached o then
				s := o.out
				if attached {READABLE_STRING_32} s as s32 then
					Io.put_string_32 (s32)
				elseif attached {READABLE_STRING_8} s as s8 then
					Io.put_string (s8)
				else
					Io.put_string_32 (s.as_string_32)
				end
			end
		ensure -- from ANY
			instance_free: class
		end

	frozen tagged_out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			tagged_out_not_void: Result /= Void
		end
	
feature -- Platform

	is_64_bits: BOOLEAN
			-- Is the current process runing in 64-bit mode
			-- (from PLATFORM)
		external
			"built_in static"
		ensure -- from PLATFORM
			instance_free: class
		end

	is_dotnet: BOOLEAN
			-- Are we targetting .NET?
			-- (from PLATFORM)
		external
			"built_in static"
		ensure -- from PLATFORM
			instance_free: class
		end

	Is_little_endian: BOOLEAN
			-- Is current platform a little endian one?
			-- (from PLATFORM)
		local
			l_nat16: NATURAL_16
			l_nat8: NATURAL_8
			l_first: NATURAL_8
		once
			l_nat16 := 17185
			l_nat8 := 33;
			($l_first).memory_copy ($l_nat16.to_pointer, 1)
			Result := l_first = l_nat8
		ensure -- from PLATFORM
			instance_free: class
		end

	is_mac: BOOLEAN
			-- Are we running on Mac OS?
			-- (from PLATFORM)
		external
			"built_in static"
		ensure -- from PLATFORM
			instance_free: class
		end

	is_scoop_capable: BOOLEAN
			-- Is current platform capable of SCOOP?
			-- (from PLATFORM)
		external
			"built_in static"
		ensure -- from PLATFORM
			instance_free: class
		end

	is_thread_capable: BOOLEAN
			-- Is current platform capable of multi-threading?
			-- (from PLATFORM)
		external
			"built_in static"
		ensure -- from PLATFORM
			instance_free: class
		end

	is_unix: BOOLEAN
			-- Are we running on a Unix like platform?
			-- (from PLATFORM)
		external
			"built_in static"
		ensure -- from PLATFORM
			instance_free: class
		end

	is_vms: BOOLEAN
			-- Are we running on VMS?
			-- (from PLATFORM)
		external
			"built_in static"
		ensure -- from PLATFORM
			instance_free: class
		end

	is_vxworks: BOOLEAN
			-- Are we running on VxWorks?
			-- (from PLATFORM)
		external
			"built_in static"
		ensure -- from PLATFORM
			instance_free: class
		end

	is_windows: BOOLEAN
			-- Are we running on Windows platform?
			-- (from PLATFORM)
		external
			"built_in static"
		ensure -- from PLATFORM
			instance_free: class
		end

	Operating_environment: OPERATING_ENVIRONMENT
			-- Objects available from the operating system
			-- (from ANY)
		once
			create Result
		ensure -- from ANY
			instance_free: class
			operating_environment_not_void: Result /= Void
		end
	
feature {NONE} -- Retrieval

	frozen internal_correct_mismatch
			-- Called from runtime to perform a proper dynamic dispatch on correct_mismatch
			-- from MISMATCH_CORRECTOR.
			-- (from ANY)
		local
			l_msg: STRING_32
			l_exc: EXCEPTIONS
		do
			if attached {MISMATCH_CORRECTOR} Current as l_corrector then
				l_corrector.correct_mismatch
			else
				create l_msg.make_from_string ("Mismatch: ".as_string_32)
				create l_exc;
				l_msg.append (generating_type.name_32);
				l_exc.raise_retrieval_exception (l_msg)
			end
		end
	
feature -- Settings

	set_from_pointer (a_ptr: POINTER; n: INTEGER_32)
			-- Use directly a_ptr with count n to hold current data.
		require
			is_shared: is_shared
			a_ptr_not_null: a_ptr = default_pointer implies n = 0
			n_non_negative: n >= 0
		do
			item := a_ptr
			count := n
		ensure
			item_set: item = a_ptr
			count_set: count = n
			is_shared_unchanged: is_shared
		end
	
invariant
	item_not_null: item = default_pointer implies (count = 0 and is_shared)
	valid_count: count >= 0

		-- from ANY
	reflexive_equality: standard_is_equal (Current)
	reflexive_conformance: conforms_to (Current)

note
	copyright: "Copyright (c) 1984-2020, Eiffel Software and others"
	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
	source: "[
		Eiffel Software
		5949 Hollister Ave., Goleta, CA 93117 USA
		Telephone 805-685-1006, Fax 805-685-6869
		Website http://www.eiffel.com
		Customer support http://support.eiffel.com
	]"

end -- class MANAGED_POINTER

Generated by ISE EiffelStudio