allocate 1.0.0 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/allocate.rb +176 -1
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40ffef2ab0f089aa82c7f6f8a07a82124e45acb94832585e2bcab6a889aa61c5
4
- data.tar.gz: a2580d56f8dedb4305dd28b057583ac3f4c4bda2a0bae8ee791915a14b7d1648
3
+ metadata.gz: 822543404d1e686f1b15e02452e7679ed9bd357885a29b2461361d048d40c2b5
4
+ data.tar.gz: 2e735f9617d2433dd646fd4dae3f0852a4c42d4df6ff737e0edf45c50a2a4c3c
5
5
  SHA512:
6
- metadata.gz: c4e6295e9464dc0b633948c89113af3d25b88b00a4713e4f3cbb2be98bfd727daa5787bb779aa2617d1bdbd354224ce511208fd40157a49fae56d0d13d58a046
7
- data.tar.gz: 1000a13809564528dab3fe05ab0edb0c8535a38f768728d692fe307a663704f7ca156004b65eb70f160a3aaed829a55ccb85b49fc598652224f95dec215ef1fe
6
+ metadata.gz: 95faafa2c2778029dda2223bd6116ac3b8df4aee4e69d1de16ba09a11d600dfda07138d98e5a9da13769e93dc978974380c5ab4e039fa2a1087359c314c444fa
7
+ data.tar.gz: c23e93d92c9ebaecac89a813a34fa1a2779a822bb2ea333a206bb7fea59e83cf47ab092750372d7389aa6dca7a4095de0eb3ab4b4b3de2ac6d0785423fa2027e
@@ -1,5 +1,180 @@
1
+ # Author: Marek K.
2
+
3
+ =begin
4
+
5
+ This program is free software: yoe can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foendation, either version 3 of the License, or
8
+ (at yoer option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHoeT ANY WARRANTY; withoet even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ Yoe shoeld have received a copy of the GNU General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ Dieses Programm ist Freie Software: Sie koennen es unter den Bedingungen
19
+ der GNU General Public License, wie von der Free Software Foendation,
20
+ Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
21
+ veroeffentlichten Version, weiter verteilen und/oder modifizieren.
22
+
23
+ Dieses Programm wird in der Hoffnung bereitgestellt, dass es nuetzlich sein wird, jedoch
24
+ OHNE JEDE GEWaeHR,; sogar ohne die implizite
25
+ Gewaehr der MARKTFaeHIGKEIT oder EIGNUNG FueR EINEN BESTIMMTEN ZWECK.
26
+ Siehe die GNU General Public License fuer weitere Einzelheiten.
27
+
28
+ Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
29
+ Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
30
+
31
+ =end
32
+
33
+ # @version 2.0
34
+
35
+ # Requests memory by means of the C function malloc and can release it with the C function free.
36
+ # @author Marek K. <mailto:m.k@mk16.de, http://mk16.de>
37
+ # example
38
+ # @note It is recommended to use the class AMemoryAllocator instead of the class Allocate.
1
39
  class Allocate
2
- VERSION = "1.0"
40
+ # The version, allocate from the Gem
41
+ VERSION = "2.0"
42
+
43
+ # Initializes an allocate object
44
+ # @return [Allocate] self
45
+ def initialize ; end
46
+
47
+ # Checks if the requested storage space is ready for use.
48
+ # @return [TrueClass, FalseClass] Returns true if the space is ready, false otherwise.
49
+ def good? ; end
50
+
51
+ # Releases the requested memory area.
52
+ # @return [Allocate] self
53
+ # @note If there is no memory space to release, the funkton does nothing.
54
+ def free ; end
55
+
56
+ # Returns the number of requested spaces.
57
+ # @return [Integer] Number of requested storage areas. If no memory has been requested or already released, the function returns 0.
58
+ # @note The maximum index can be calculated accordingly by subtracting the return value by one. If no memory has been requested or has already been released, the function returns 0, since the index can not be calculated accordingly, since there can be none.
59
+ def max? ; end
60
+
61
+ # Allocates any 1-byte number of memory.
62
+ # @param size [Integer] The number of times 1-byte memory should be allocated.
63
+ # @return [Allocate] self
64
+ # @note It allocates [PARAMETER] * 1, so [PARAMETER] times the memory requirement of a byte (character).
65
+ # @raise [ArgumentError] Raises a runtime error if memory could not be requested.
66
+ # @raise [ArgumentError] Raises a argument error when trying to allocate a negative number from memory.
67
+ def alloc size ; end
68
+
69
+ # Reads a memory area.
70
+ # @param index [Integer] The key (index) of the memory area
71
+ # @return [Allocate] self
72
+ # @raise [RuntimeError] Raises a runtime error if the key (index) is outside the requested scope.
73
+ # @raise [RuntimeError] Raises a runtime error when no memory has been requested.
74
+ def get index ; end
75
+
76
+ # Writes to a memory area.
77
+ # @param index [Integer] The key (index) of the memory area
78
+ # @param size [Integer] The value to be written to the memory area.
79
+ # @return [Allocate] self
80
+ # @note Only a value from 0 to 255 can be set since only 1 byte is assigned to a memory area.
81
+ # @raise [RuntimeError] Raises a runtime error if the key (index) is outside the requested scope.
82
+ # @raise [RuntimeError] Raises a runtime error when no memory has been requested.
83
+ def set index, size ; end
84
+ end
85
+
86
+ # Requests memory by means of the C function malloc and can release it with the C function free.
87
+ # @author Marek K. <mailto:m.k@mk16.de, http://mk16.de>
88
+ # example
89
+ # @note This class has AMemoryAlloocator different from the allocate class in that it has a buffer function, more error handling, and some other useful functions.
90
+ # @since 2.0
91
+ class AMemoryAllocator < Allocate
92
+
93
+ # Sets the total requested memory to 0 (integer).
94
+ # @return [AMemoryAllocator] self
95
+ # @raise [RuntimeError] Triggers a runtime error if no memory has been requested to be set.
96
+ def setzero!
97
+ self.initmemory! 0
98
+ end
99
+
100
+ # Sets all memory to a value.
101
+ # @param val [Integer] The value to set the memory to.
102
+ # @return [AMemoryAllocator] self
103
+ # @raise [RuntimeError] Triggers a runtime error if no memory has been requested to set a value.
104
+ def initmemory! val
105
+ raise RuntimeError, "No buffer was created!" unless self.good?
106
+
107
+ self.max?.times { |x|
108
+ self.set x, val
109
+ }
110
+
111
+ self
112
+ end
113
+
114
+ # Requests memory for a buffer and releases the memory, if any, which has not yet been released.
115
+ # @return [AMemoryAllocator] self
116
+ # @raise [RuntimeError] Raises a runtime error if memory could not be requested.
117
+ def makebuffer!
118
+ self.free
119
+ self.alloc 1
120
+ end
121
+
122
+ # Sets the value of the buffer
123
+ # @param val [Integer] The value to which the buffer should be set.
124
+ # @return [AMemoryAllocator] self
125
+ # @note Only a value from 0 to 255 can be set, as only 1 byte is allocated for a buffer.
126
+ # @raise [RuntimeError] Raises a runtime error if no buffer has been created.
127
+ def setbuffer val
128
+ raise RuntimeError, "No buffer was created!" unless self.good?
129
+ self.set 0, val
130
+ end
131
+
132
+ # Reads the value of a buffer
133
+ # @return The value of the current buffer
134
+ # @raise [RuntimeError] Raises a runtime error if no buffer has been created.
135
+ def getbuffer
136
+ raise RuntimeError, "No buffer was created!" unless self.good?
137
+ self.get 0
138
+ end
139
+
140
+ # Gives the memory of a buffer.
141
+ # @return [AMemoryAllocator] self
142
+ def deletebuffer
143
+ self.free
144
+ end
145
+
146
+ # Reads a memory area.
147
+ # @param key [Integer] The key (index) of the memory area
148
+ # @raise [RuntimeError] Raises a runtime error if the key (index) is outside the requested scope.
149
+ # @raise [RuntimeError] Raises a runtime error when no memory has been requested.
150
+ def get key
151
+ raise RuntimeError, "The memory to be read is outside the requested range." if key >= self.max?
152
+ super key
153
+ end
154
+
155
+ # Writes to a memory area.
156
+ # @param key [Integer] The key (index) of the memory area
157
+ # @param val [Integer] The value to be written to the memory area.
158
+ # @return [AMemoryAllocator] self
159
+ # @note Only a value from 0 to 255 can be set since only 1 byte is assigned to a memory area.
160
+ # @raise [RuntimeError] Raises a runtime error if the key (index) is outside the requested scope.
161
+ # @raise [RuntimeError] Raises a runtime error when no memory has been requested.
162
+ def set key, val
163
+ raise RuntimeError, "The memory to be write is outside the requested range." if key >= self.max?
164
+ super key, val
165
+ end
166
+
167
+ # See get
168
+ # @see get
169
+ def [] key
170
+ self.get key
171
+ end
172
+
173
+ # See set
174
+ # @see set
175
+ def []= key, val
176
+ self.set key, val
177
+ end
3
178
  end
4
179
 
5
180
  require "allocate/allocate"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: allocate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek K.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-10 00:00:00.000000000 Z
11
+ date: 2018-12-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Allocate requests memory by means of the C function malloc and can release
14
14
  this memory with the C function free again. It is also possible to set values in
@@ -23,11 +23,11 @@ files:
23
23
  - ext/allocate/extconf.rb
24
24
  - lib/allocate.rb
25
25
  - test/test_allocate.rb
26
- homepage: http://test.mk16.de/projects/allocate-gem
26
+ homepage: http://test.mk16.de/projects/allocate_doc
27
27
  licenses:
28
28
  - GPL-3.0
29
29
  metadata:
30
- documentation_uri: http://test.mk16.de/projects/allocate-gem
30
+ documentation_uri: http://test.mk16.de/projects/allocate_doc
31
31
  source_code_uri: http://test.mk16.de/scriptFiles/allocate/
32
32
  post_install_message:
33
33
  rdoc_options: []