trying to build a RAM class... need knowledge

This is the place for queries that don't fit in any of the other categories.

trying to build a RAM class... need knowledge

Postby Tcll » Thu Jan 23, 2014 2:25 pm

so, I need a class that can act as virtual RAM...
reason being, I've needed pointer simulation for address verification for quite a while now... heh

so what methods would I need and how would I need to build the __init__() method??

here's what I have so far: (originally started as a file class)
Code: Select all
from array import array as _arr #private

class MEM:
    def __init__(this):
        this.data = _arr('B',[]) #fastest possible safe array for data management
        this.size = 0
        this.offset = 0

    def preread(this,length=this.size): return this.data[this.offset:this.offset+length]
    def read(this,length=this.size): return this.data[this.offset:this.offset+length]; this.offset+=length
    def alloc(this,size): pass #save up some memory before writing (speed things up a bit)
    def write(this,char=''): pass


why the array module?
aside from it being fastest array I've used yet (including NumPy), I find it better to parse both types of file-data as 8bit ints

the only faster thing I know of is a dictionary, but that's unsafe as it eats a massive amount of memory for a large amount of data

anyways, if there's anything I don't know, please tell me :)
(if I already know it, tell me anyways) :P

if anyone knows of any previous topics here, or other information on something similar to this,
please post a link. :)

OT: /new idea >.>
I should build a script that tests each type of array with [].append(v) and []+=[v]
(who's not to say my previous tests havn't changed over time as Py27 evolved)
User avatar
Tcll
 
Posts: 100
Joined: Wed Jan 01, 2014 6:36 pm

Re: trying to build a RAM class... need knowledge

Postby Mekire » Thu Jan 23, 2014 3:21 pm

If you want Python to not be Python, why use Python?

-Mek
User avatar
Mekire
 
Posts: 987
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: trying to build a RAM class... need knowledge

Postby Tcll » Thu Jan 23, 2014 3:38 pm

Mekire wrote:If you want Python to not be Python, why use Python?

-Mek

I don't want it to NOT be python...

I like python for it's simplicity...

what I need to do is test and verify the files I'm importing or exporting...
these files use pointer addresses and memory-managed sections similar to raw RAM data

so, all I need is an interface to work with them, so I can foreward this interface's methods to the sub-interface of my program

the extendable scripts for my program are python-based with extended functions for data management.
(the import statement is not recommended for use in my scripts, but it's not completely bamf'd either)
^ reason being is with anything imported, you'll need to grab all the file data from the internal interface of my program before you can use it

the reason for an internal data hander, rather than a python-managed data handler:
viewtopic.php?f=10&t=10196
^I have methods for handling 5-byte (any byte-size really) IEEE754-encoded float values, and just need an extended data handler to control everything

this class is really only for file management of non-specific data methods...
the "pointers" are only local to the file or memory-space... (for validation or other purposes)
I don't need them entirely for my program... heh

thanks for being concerned though :)
User avatar
Tcll
 
Posts: 100
Joined: Wed Jan 01, 2014 6:36 pm

Re: trying to build a RAM class... need knowledge

Postby Tcll » Thu Jan 23, 2014 4:56 pm

old ideas: http://tcll5850.proboards.com/thread/18 ... ions-ideas

been asking for a hand in this for a nearly a year now actually...

what would I need to do to get everything working??
User avatar
Tcll
 
Posts: 100
Joined: Wed Jan 01, 2014 6:36 pm

Re: trying to build a RAM class... need knowledge

Postby hrs » Fri Jan 24, 2014 1:14 pm

What task should your program perform from the point of view of an end user? Or is this just your personal exercize in working with pointers or ... (I realy have no idea)?

edit:
What do you mean by
what I need to do is test and verify the files I'm importing or exporting...

Is it something you couldn't do with a parser?
Last edited by hrs on Fri Jan 24, 2014 1:24 pm, edited 1 time in total.
hrs
 
Posts: 86
Joined: Thu Feb 07, 2013 9:26 pm

Re: trying to build a RAM class... need knowledge

Postby Kebap » Fri Jan 24, 2014 1:21 pm

I don't know, but I noticed something else. You wrote:

Code: Select all
def read(this,length=this.size): return this.data[this.offset:this.offset+length]; this.offset+=length


I think this translates to:

Code: Select all
def read(this, length = this.size):
    return this.data[this.offset:this.offset + length]
    this.offset += length


Where the second line will never get executed, as return ends the function.
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 394
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: trying to build a RAM class... need knowledge

Postby Tcll » Fri Jan 24, 2014 2:21 pm

Kebap wrote:I don't know, but I noticed something else. You wrote:

Code: Select all
def read(this,length=this.size): return this.data[this.offset:this.offset+length]; this.offset+=length


I think this translates to:

Code: Select all
def read(this, length = this.size):
    return this.data[this.offset:this.offset + length]
    this.offset += length


Where the second line will never get executed, as return ends the function.


oops, thanks :)
I only did a quick write-up to edit later... nothing in there is final. XD

hrs wrote:What task should your program perform from the point of view of an end user? Or is this just your personal exercize in working with pointers or ... (I realy have no idea)?

edit:
What do you mean by
what I need to do is test and verify the files I'm importing or exporting...

Is it something you couldn't do with a parser?


sorry... I should've explained a bit further...

what I mean is that some files, such as the HAL .DAT format, work entirely off pointers and need to store the structure before setting the pointer to that structure.
any valid (not 0) pointers are logged in an array table as pointers to those pointers.

without pointer simulation for verification, other files that need it would be extremely complex to parse and write...


why do I NOT call this a file class?
while it's purpose IS for handling file data from various files,
it's meant to act as RAM with extended storage and data features.

but the question still remains...
how could I access the array to get it's updated pointers to the data in real-time??
as well as what functions would I need for accessing the data??

in C++ IK malloc() is for allocating memory in the RAM for the data you're about to fill it with... (IDK much about C++)
so that's the purpose of the alloc() function.

preread() is for testing data before reading it.

would I need any other special functions like that??


and the final thing...
in my posted link to my forum's ideas for this:
how could I get ref() and deref() working appropriately??

such as if you wanted to do:
Code: Select all
 ...

data = bu32() #creates a bu32 object until this value (from the memory object) is modified
dptr = ref(data) #gets our dynamic address of the bu32 object

other_data = deref( dptr-4 ) #not sure how I could simulate this appropriately
#since my idea is a dictionary for the addresses storing a reference to the data object
User avatar
Tcll
 
Posts: 100
Joined: Wed Jan 01, 2014 6:36 pm

Re: trying to build a RAM class... need knowledge

Postby Tcll » Fri Jan 24, 2014 11:29 pm

OH, I think I understand what I would need to do: :o
Code: Select all
data = bu32() #read a big, unsigned, 4-byte int
dataptr = ref(data)

value = deref(address=dataptr, struct=bu32)

with that, I guess you could work with it just like C:
Code: Select all
int data = bu32()
int *dataptr = &data //not sure if the * is needed or not... I've seen both examples

int value = *dataptr


where my python version would be superior:
Code: Select all
value = deref( 0, bu(5) ) #take a guess :P

so if I'm right, dereferencing is just like:
Code: Select all
jump(0)
value = bu(5)()

am I right??
(excluding the fact that dereferencing deals with actual RAM, not file data)
User avatar
Tcll
 
Posts: 100
Joined: Wed Jan 01, 2014 6:36 pm

Re: trying to build a RAM class... need knowledge

Postby Tcll » Sat Jan 25, 2014 5:24 pm

may I request this thread be moved to "Coding Help" please :)
-- moved --

also... I've pretty much figured out how to get my pointer system working
Skype: DarkPikachu wrote:[12:03:08 PM] DarkPikachu: bu32() contains _set(), but not set()
[12:07:42 PM] DarkPikachu:
def _deref_set(this, value): this._set(value)

def deref(addr, struct):
global offset; offset = addr
value = struct()
value.set = _deref_set
return value

[12:08:26 PM] DarkPikachu: where we define bu32().set() w/in deref() only for the returned instance

[12:10:52 PM] DarkPikachu: results:

>>> data = bu32()
>>> data.set( 0 )
Traceback

>>> deref( 0, bu32 ).set( 0 )
>>>


if course though I'd have to get the current memory object to read the data from and such :P
User avatar
Tcll
 
Posts: 100
Joined: Wed Jan 01, 2014 6:36 pm

Re: trying to build a RAM class... need knowledge

Postby Tcll » Thu Jan 30, 2014 6:01 am

alright... so apparently this is possible in C++
Code: Select all
d = bu32() # 32
p = ref(d)
deref( p, bu16 ).set( 16 )


expected results:
Code: Select all
>>> d
16
>>> type( d ) # bu16 == bu(2); bu32 == bu(4)
<class '__main__.bu(2)'>
>>> #internal fle data: 00 10 00 20 (like in C++)


how could I make the bu32 class replace it's instance with a bu16 instance??

EDIT: perhaps I needed to create a new topic to ask this :/

EDIT2: a more detailed explanation
http://www.daniweb.com/software-develop ... ost2061378
User avatar
Tcll
 
Posts: 100
Joined: Wed Jan 01, 2014 6:36 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 4 guests