Skip to content

Commit 4e30e6f

Browse files
committed
add MemoryMappedFile definition for cpp
1 parent 4f7c130 commit 4e30e6f

File tree

6 files changed

+254
-4
lines changed

6 files changed

+254
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ test30G_pixels/
2323
*.csv
2424
resources/*.xml
2525
*.so
26+
*.o
2627
.vscode

cpp/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
all: NativePixelsCacheReader
1+
all: PixelsCacheReader
22

3-
NativePixelsCacheReader:
3+
PixelsCacheReader: PixelsCacheReader.cc MemoryMappedFile
44
$(CXX) -shared -fPIC $@.cc -o lib_pixels.so -I/usr/lib/jvm/java-1.8.0-openjdk-amd64/include/ -I/usr/lib/jvm/java-8-openjdk-amd64/include/linux/
55

6+
MemoryMappedFile:
7+
$(CXX) -c $@.cc
8+
69
clean:
7-
rm -rf ./lib_pixels.so
10+
rm -rf ./lib_pixels.so ./*.o

cpp/MemoryMappedFile.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include <iostream>
2+
#include "MemoryMappedFile.h"

cpp/MemoryMappedFile.h

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
#ifndef MemoryMappedFile_H
2+
#define MemoryMappedFile_H
3+
4+
#include <string>
5+
6+
using namespace std;
7+
8+
typedef char byte;
9+
10+
class MemoryMappedFile
11+
{
12+
private:
13+
//Unsafe unsafe;
14+
//private static final Method mmap;
15+
//Method unmmap;
16+
static int BYTE_ARRAY_OFFSET;
17+
18+
long addr, size;
19+
string loc;
20+
21+
static long roundTo4096(long i)
22+
{
23+
return (i + 0xfffL) & ~0xfffL;
24+
}
25+
26+
void mapAndSetOffset()
27+
{
28+
}
29+
30+
public:
31+
/**
32+
* Constructs a new memory mapped file.
33+
*
34+
* @param loc the file name
35+
* @param len the file length
36+
* @throws Exception in case there was an error creating the memory mapped file
37+
*/
38+
MemoryMappedFile(string &loc, long len)
39+
{
40+
loc = loc;
41+
size = roundTo4096(len);
42+
mapAndSetOffset();
43+
}
44+
45+
void unmap()
46+
{
47+
}
48+
49+
/**
50+
* Reads a byte from the specified position.
51+
*
52+
* @param pos the position in the memory mapped file
53+
* @return the value read
54+
*/
55+
byte getByte(long pos)
56+
{
57+
return 0;
58+
}
59+
60+
/**
61+
* Reads a byte (volatile) from the specified position.
62+
*
63+
* @param pos the position in the memory mapped file
64+
* @return the value read
65+
*/
66+
byte getByteVolatile(long pos)
67+
{
68+
return 0;
69+
}
70+
71+
short getShort(long pos)
72+
{
73+
return 0;
74+
}
75+
76+
short getShortVolatile(long pos)
77+
{
78+
return 0;
79+
}
80+
81+
/**
82+
* Reads an int from the specified position.
83+
*
84+
* @param pos the position in the memory mapped file
85+
* @return the value read
86+
*/
87+
int getInt(long pos)
88+
{
89+
return 0;
90+
}
91+
92+
/**
93+
* Reads an int (volatile) from the specified position.
94+
*
95+
* @param pos position in the memory mapped file
96+
* @return the value read
97+
*/
98+
int getIntVolatile(long pos)
99+
{
100+
return 0;
101+
}
102+
103+
/**
104+
* Reads a long from the specified position.
105+
*
106+
* @param pos position in the memory mapped file
107+
* @return the value read
108+
*/
109+
long getLong(long pos)
110+
{
111+
return 0;
112+
}
113+
114+
/**
115+
* Reads a long (volatile) from the specified position.
116+
*
117+
* @param pos position in the memory mapped file
118+
* @return the value read
119+
*/
120+
long getLongVolatile(long pos)
121+
{
122+
return 0;
123+
}
124+
125+
/**
126+
* Writes a byte to the specified position.
127+
*
128+
* @param pos the position in the memory mapped file
129+
* @param val the value to write
130+
*/
131+
void putByte(long pos, byte val)
132+
{
133+
}
134+
135+
void putBytes(long pos, byte* val, int length)
136+
{
137+
for (int i = 0; i < length ; ++i)
138+
{
139+
140+
}
141+
}
142+
143+
/**
144+
* Writes a byte (volatile) to the specified position.
145+
*
146+
* @param pos the position in the memory mapped file
147+
* @param val the value to write
148+
*/
149+
void putByteVolatile(long pos, byte val)
150+
{
151+
}
152+
153+
void putShort(long pos, short val)
154+
{
155+
}
156+
157+
void putShortVolatile(long pos, short val)
158+
{
159+
}
160+
161+
/**
162+
* Writes an int to the specified position.
163+
*
164+
* @param pos the position in the memory mapped file
165+
* @param val the value to write
166+
*/
167+
void putInt(long pos, int val)
168+
{
169+
}
170+
171+
/**
172+
* Writes an int (volatile) to the specified position.
173+
*
174+
* @param pos the position in the memory mapped file
175+
* @param val the value to write
176+
*/
177+
void putIntVolatile(long pos, int val)
178+
{
179+
}
180+
181+
/**
182+
* Writes a long to the specified position.
183+
*
184+
* @param pos the position in the memory mapped file
185+
* @param val the value to write
186+
*/
187+
void putLong(long pos, long val)
188+
{
189+
}
190+
191+
/**
192+
* Writes a long (volatile) to the specified position.
193+
*
194+
* @param pos the position in the memory mapped file
195+
* @param val the value to write
196+
*/
197+
void putLongVolatile(long pos, long val)
198+
{
199+
}
200+
201+
/**
202+
* Reads a buffer of data.
203+
*
204+
* @param pos the position in the memory mapped file
205+
* @param data the input buffer
206+
* @param offset the offset in the buffer of the first byte to read data into
207+
* @param length the length of the data
208+
*/
209+
void getBytes(long pos, byte* data, int offset, int length)
210+
{
211+
}
212+
213+
/**
214+
* Writes a buffer of data.
215+
*
216+
* @param pos the position in the memory mapped file
217+
* @param data the output buffer
218+
* @param offset the offset in the buffer of the first byte to write
219+
* @param length the length of the data
220+
*/
221+
void setBytes(long pos, byte* data, int offset, int length)
222+
{
223+
}
224+
225+
bool compareAndSwapInt(long pos, int expected, int value)
226+
{
227+
}
228+
229+
bool compareAndSwapLong(long pos, long expected, long value)
230+
{
231+
}
232+
233+
long getAndAddLong(long pos, long delta)
234+
{
235+
}
236+
237+
long getSize()
238+
{
239+
return size;
240+
}
241+
};
242+
243+
#endif
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <iostream>
2-
#include "NativePixelsCacheReader.h"
2+
#include "PixelsCacheReader.h"
3+
#include "MemoryMappedFile.h"
34
using namespace std;
45

56
JNIEXPORT jbyteArray JNICALL Java_cn_edu_ruc_iir_pixels_cache_NativePixelsCacheReader_get

0 commit comments

Comments
 (0)