4pie0
4pie0

Reputation: 29724

Raw memory access Java/Python

Memory-mapped hardware

On some computing architectures, pointers can be used to directly manipulate memory or memory-mapped devices.

Assigning addresses to pointers is an invaluable tool when programming microcontrollers. Below is a simple example declaring a pointer of type int and initialising it to a hexadecimal address in this example the constant 0x7FFF:

int *hardware_address = (int *)0x7FFF;

In the mid 80s, using the BIOS to access the video capabilities of PCs was slow. Applications that were display-intensive typically used to access CGA video memory directly by casting the hexadecimal constant 0xB8000 to a pointer to an array of 80 unsigned 16-bit int values. Each value consisted of an ASCII code in the low byte, and a colour in the high byte. Thus, to put the letter 'A' at row 5, column 2 in bright white on blue, one would write code like the following:

#define VID ((unsigned short (*)[80])0xB8000)

void foo() {
    VID[4][1] = 0x1F00 | 'A';
}

is such thing possible in Java/Python in the absence of pointers?

EDIT:

is such an acces possible:

char* m_ptr=(char*)0x603920;
printf("\nm_ptr: %c",*m_ptr);

?

Upvotes: 1

Views: 1221

Answers (2)

bmargulies
bmargulies

Reputation: 100033

If you are on an operating system with /dev/mem, you can create a MappedByteBuffer onto it and do this sort of thing.

Upvotes: 1

Jeff Ferland
Jeff Ferland

Reputation: 18292

I'm totally uncertain of the context and thus useful application of what you're trying to do, but here goes:

The Java Native Interface should allow direct memory access within the process space. Similarly, python can load c module that would provide an access method.

Unless you've got a driver loaded by the system to do the interfacing, however, any hardware device memory will be out-of-bounds. Even then, the driver / kernel module must be the one to address non-application space memory.

Upvotes: 3

Related Questions