COVERAGE SUMMARY
FILE SUMMARY
NameExecutedRoutines%ExecutedLines%Unexecuted
/home/matt/eu/rds/include/std/eumem.e33100.00%313588.57%4
ROUTINE SUMMARY
RoutineExecutedLinesUnexecuted
malloc()121485.71%2
valid()101283.33%2
free()66100.00%0
LINE COVERAGE DETAIL
#Executed
1
-- (c) Copyright - See License.txt
2
--
3
--****
4
-- == Pseudo Memory
5
--
6
--
7
-- One use is to emulate PBR, such as Euphoria's map and stack types.
8
--
9
-- <>
10
11
namespace eumem
12
13
--**
14
-- The (pseudo) RAM heap space. Use [[:malloc]] to gain ownership to a heap location
15
-- and [[:free]] to release it back to the system.
1622
export sequence ram_space = {}
17
1822
integer ram_free_list = 0
19
integer free_rid
20
21
--**
22
-- Allocate a block of (pseudo) memory
23
--
24
-- Parameters:
25
-- # ##mem_struct_p## : The initial structure (sequence) to occupy the allocated
26
-- block. If this is an integer, a sequence of zero this long is used. The default
27
-- is the number 1, meaning that the default initial structure is {0}
28
-- # ##cleanup_p## : Identifies whether the memory should be released automatically
29
-- when the reference count for the handle for the allocated block drops to
30
-- zero, or when passed to ##delete()##. If 0, then the block must be freed
31
-- using the [[:free]] procedure.
32
--
33
-- Returns:
34
-- A **handle**, to the acquired block. Once you acquire this, you can use it as you
35
-- need to. Note that if ##cleanup_p## is 1, then the variable holding the
36
-- handle must be capable of storing an atom as a double floating point value
37
-- (i.e., not an integer).
38
--
39
-- Example 1:
40
--
41
-- my_spot = malloc()
42
-- ram_space[my_spot] = my_data
43
--
44
4584
46
integer temp_
47
4884
if atom(mem_struct_p) then
4984
mem_struct_p = repeat(0, mem_struct_p)
50
end if
5184
if ram_free_list = 0 then
5241
ram_space = append(ram_space, mem_struct_p)
5341
if cleanup_p then
5441
return delete_routine( length(ram_space), free_rid )
55
else
560
return length(ram_space)
57
end if
58
end if
59
6043
temp_ = ram_free_list
6143
ram_free_list = ram_space[temp_]
6243
ram_space[temp_] = mem_struct_p
63
6443
if cleanup_p then
6543
return delete_routine( temp_, free_rid )
66
else
670
return temp_
68
end if
69
end function
70
71
--**
72
-- Deallocate a block of (pseudo) memory
73
--
74
-- Parameters:
75
-- # ##mem_p## : The handle to a previously acquired [[:ram_space]] location.
76
--
77
-- Comments:
78
-- This allows the location to be used by other parts of your application. You
79
-- should no longer access this location again because it could be acquired by
80
-- some other process in your application. This routine should only be called
81
-- if you passed 0 as ##cleanup_p## to [[:malloc]].
82
--
83
-- Example 1:
84
--
85
-- my_spot = malloc(1,0)
86
-- ram_space[my_spot] = my_data
87
-- -- . . . do some processing . . .
88
-- free(my_spot)
89
--
90
9149
9249
if mem_p < 1 then return end if
9349
if mem_p > length(ram_space) then return end if
94
9549
ram_space[mem_p] = ram_free_list
9649
ram_free_list = floor(mem_p)
9749
end procedure
9822
free_rid = routine_id("free")
99
100
--**
101
-- Validates a block of (pseudo) memory
102
--
103
-- Parameters:
104
-- # ##mem_p## : The handle to a previously acquired [[:ram_space]] location.
105
-- # ##mem_struct_p## : If an integer, this is the length of the sequence that
106
-- should be occupying the ram_space location pointed to by ##mem_p##.
107
--
108
-- Returns:
109
-- An **integer**,\\
110
-- 0 if either the ##mem_p## is invalid or if the sequence at that location is
111
-- the wrong length.\\
112
-- 1 if the handle and contents is okay.
113
--
114
-- Comments:
115
-- This can only check the length of the contents at the location. Nothing else
116
-- is checked at that location.
117
--
118
-- Example 1:
119
--
120
-- my_spot = malloc()
121
-- ram_space[my_spot] = my_data
122
-- . . . do some processing . .
123
-- if valid(my_spot, length(my_data)) then
124
-- free(my_spot)
125
-- end if
126
--
127
1285422
1295422
if not integer(mem_p) then return 0 end if
1305421
if mem_p < 1 then return 0 end if
1315414
if mem_p > length(ram_space) then return 0 end if
132
1335414
if sequence(mem_struct_p) then return 1 end if
134
1352
if atom(ram_space[mem_p]) then
1361
if mem_struct_p >= 0 then
1371
return 0
138
end if
139
1400
return 1
141
end if
142
1431
if length(ram_space[mem_p]) != mem_struct_p then
1440
return 0
145
end if
146
1471
return 1
148
end function