|
AddressSpace library v1.0 beta | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--AddressSpace
This class rapresents a virtual address space.
I decided to develop this module to make it possible to have a lot of
data available and memorized in a persisten way.
Structured files are very performing if tailored for a specific appication
but are difficult to manage and an hardly reusable
code resource.
A natural alternative is a virtual memory implementation.
Every instance is connected to a data file (extension .asd) and to an
index file (extension .asi).
The former is responsible for containing the data, the latter contains informations
relatives to data storing and pages organization.
Access to the data file is achieved using read and write call on the
swapping space object.
The swap space is responsible for allocating new pages and retrieving old ones
from the data file.
Data (both index and real data) are stored in 4 Kbytes pages.
The index file is made up of a first page called master index page,
where are stored integer referring to positions of other pages inside the
index file following the master index, those pages are referred as
secondary index pages.
Inside a secondary index page integers are stored to locate a data page
inside the data file.
The adressing is made by 32 bit words, where the first 20 bits are relative
to the page, the latest 12 are relative to the byte inside the page.
The first ten bits of the address are used inside the master index page to
locate the position of the secondary index page, the following ten bits are
used to locate the data page inside the data file.
By convention a number 0 means that the page is not (yet) present in
the addressing space.
Pages are cached by the application, when the user create the instance the
number of pages to remain in central memory can be provided.
Cache can be modifyed dinamically during operations and is digested in
a Least Recently Used algorithm.
Inside the swapping space the caches are connected to synching threads
that are responsible to keed memory and disk images synched on a
timed basis.
BEWARE
no tools for data integrity are provided
they will in a future release.
Constructor Summary | |
AddressSpace(java.lang.String filename)
Connect to an already existing address space. |
|
AddressSpace(java.lang.String filename,
int cacheSizeInKB)
Connect to an already existing address space. |
Method Summary | |
void |
close()
Close the address space. |
static void |
createSpace(java.lang.String spaceName)
Create a new empty swap space. |
static void |
createSpace(java.lang.String spaceName,
java.lang.String informations)
Create a new empty swap space. |
void |
dumpCache(java.lang.String fileName)
Create a file image of the data cache in a human-reqadable format. |
byte |
read(int offset)
Read a byte value from the address space. |
int |
read(int offset,
byte[] buffer)
Read a byte array from the address space. |
int |
read(int offset,
byte[] buffer,
int len)
Read a byte array from the address space until a certain amount of data is transferred. |
int |
read(int offset,
byte[] buffer,
int len,
int boffset)
Read a byte array from the address space starting from an offset until a certain amount of data is transferred. |
int |
readInt(int offset)
Read an int value from the address space. |
long |
readLong(int offset)
Read a long int value from the address space. |
short |
readShort(int offset)
Read a short int value from the address space. |
void |
setCache(int sizeInBytes)
Set the cache size. |
void |
setTimer(int newTimer)
Set timing for synchers. |
void |
shrink()
Shrink the data file purging all the empty pages. |
void |
sync()
Synchronize memory and disk images of cached pages. |
void |
trashPage(int location,
int id)
Destroy a page. |
int |
write(int offset,
byte v)
Write a byte value inside the address space. |
int |
write(int offset,
byte[] buffer)
Write a byte array inside the address space. |
int |
write(int offset,
byte[] buffer,
int len)
Write a byte array inside the address space until a certain amount of data is transferred. |
int |
write(int offset,
byte[] buffer,
int len,
int boffset)
Write a byte array inside the address space starting from an offset until a certain amount of data is transferred. |
int |
writeInt(int offset,
int value)
Write an int value inside the address space. |
int |
writeLong(int offset,
long value)
Write a long int value inside the address space. |
int |
writeShort(int offset,
short value)
Write a short int value inside the address space. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public AddressSpace(java.lang.String filename, int cacheSizeInKB) throws java.io.IOException
filename
- the name of the address space file.cacheSizeInKB
- the size of the cache.createSpace
public AddressSpace(java.lang.String filename) throws java.io.IOException
filename
- the name of the address space file.createSpace
Method Detail |
public void close() throws java.lang.InterruptedException, java.io.IOException
public void trashPage(int location, int id) throws java.io.IOException
This function is NOT intended to be used by a final user.
Will be removed in a future release.
location
- the location to mark as free inside the data file.id
- the id of the page to be trashed.public void sync() throws java.io.IOException
public void shrink() throws java.io.IOException
public void setTimer(int newTimer) throws java.lang.InterruptedException
newTimer
- secons that should pass between syncs.public void setCache(int sizeInBytes) throws java.io.IOException
sizeInBytes
- the new cache size.public void dumpCache(java.lang.String fileName)
fileName
- the file name where dump the cache.public byte read(int offset) throws java.io.IOException
offset
- the address where to read the byte from.public int write(int offset, byte v) throws java.io.IOException
offset
- the address where to write the byte.v
- the value to writepublic int read(int offset, byte[] buffer) throws java.io.IOException
offset
- the address where to read the array from.buffer
- the buffer where the data will be stored.public int write(int offset, byte[] buffer) throws java.io.IOException
offset
- the address where to write the bytes.buffer
- the buffer containing the data to transfer.public int read(int offset, byte[] buffer, int len) throws java.io.IOException
offset
- the address where to read the array from.buffer
- the buffer where the data will be stored.len
- the quantity of data to transfer.public int write(int offset, byte[] buffer, int len) throws java.io.IOException
offset
- the address where to write the bytes.buffer
- the buffer containing the data to transfer.len
- the quantity of data to transfer.public int read(int offset, byte[] buffer, int len, int boffset) throws java.io.IOException
offset
- the address where to read the array from.buffer
- the buffer where the data will be stored.len
- the quantity of data to transfer.boffset
- the offset inside the buffer.public int write(int offset, byte[] buffer, int len, int boffset) throws java.io.IOException
offset
- the address where to write the bytes.buffer
- the buffer containing the data to transfer.len
- the quantity of data to transfer.boffset
- the offset inside the buffer.public short readShort(int offset) throws NotAlignedPointer, java.io.IOException
offset
- the address where to read the data from.public int writeShort(int offset, short value) throws NotAlignedPointer, java.io.IOException
offset
- the address where to write the data.value
- the value to writepublic int readInt(int offset) throws NotAlignedPointer, java.io.IOException
offset
- the address where to read the data from.public int writeInt(int offset, int value) throws NotAlignedPointer, java.io.IOException
offset
- the address where to write the data.value
- the value to writepublic long readLong(int offset) throws NotAlignedPointer, java.io.IOException
offset
- the address where to read the data from.public int writeLong(int offset, long value) throws NotAlignedPointer, java.io.IOException
offset
- the address where to write the data.value
- the value to writepublic static void createSpace(java.lang.String spaceName)
spaceName
- the base filename to use os the swap space.public static void createSpace(java.lang.String spaceName, java.lang.String informations)
spaceName
- the base filename to use os the swap space.
|
Help is irrilevant You will be assimilated! |
|||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |