Home Articles Forums Gallery Marketplace Videos

WoodCentral Forums

Knowledge You Can Build On — Est. 1998

Have a question? Ask Woody!

OT - Question for programmers

Posts

OT - Question for programmers

#1

OT - Question for programmers

Denis Ch�nard, Orl�ans, Ont.

>Is it possible to access and write to memory directly under Windows, bypassing any API? I'm asking because we have a Linux application in which we do that, and I need to know if that's possible under Windows. Not that we want to do it, but I need to know the answer...

Apologies for such a blatantly OT question...

DC

Re: OT - Question for programmers

#2

You mean like PEEK and POKE ?

Mark Goodall - ATL - tooljunkie

>You mean like the old days in BASIC-DOS where you could PEEK (look) at the contents of actual RAM at a specific address and the POKE (put) a value in RAM?

Gosh, I don't know. I would think you could, but how easy it would be might be difficult.

Interesting question. I'll be watching the answers, if only out of curiosity.

Happy Woodworking!

Re: OT - Question for programmers

#3

Re: OT - Question for programmers

ScottS

>The answer is a definite "maybe".

Here's the thing: any C or C++ programmer can use a pointer to access any memory location they want. The only "catch" is that you're accessing virtual memory rather than physical memory. If there are specific physical memory locations you need to access (e.g. because they are tied to a hardware device), then it may be vastly more difficult.

Re: OT - Question for programmers

#4

Re: OT - Question for programmers

John K Jordan

>Don't know about today's OS, but when I was programming (with much earlier versions of Windows) we had to write drivers to access specific "hard" memory addresses such as control ports. Memory for almost everything else gets swapped in and out by the OS as needed. Each application is allocated it's own memory space and to protect the integrity of the entire OS, it will not normally let you write outside of that space. I don't think you can even write to "memory mapped" video ram directly without a driver these days, but as I said, I'm considerably out of date.

Most specialized hardware we purchased came with drivers for a particular OS and/or a development kit with a DLL and sample routines. The problem is with "legacy" hardware which does not have updated drivers due to perhaps a limited market or worse, because the maker has gone out of business. I have a $4000 NTSC video card on my shelf I used for my 3D graphics work that became worthless the day we all switched from DOS to NT because the company refused to spend the money to update the drivers. This obsolescence is the reason you can still find companies that use older computers with old operating systems to get their specific job done.

You (Denis) might get a more useful answer if you describe what it is your current application does, the hardware (if any) it uses, and the reason it needs to access memory directly. Do you need to port the software from Linux to a Win OS? If so, don't worry about it - the programmer you hire will handle the details.

Also, you might ask this on a forum related to your application, to general software development, and/or to the particular language your software uses or will use.

JKJ

Re: OT - Question for programmers

#5

Re: OT - Question for programmers

Pat Riley

>The short answer is 'Yes' it can be done. It depends on the memory you are trying to write to as to how go about doing it.

This very thing is that makes Windows Vista seem like such a crappy OS. A lot of software (not just hacker stuff, but major software firms) use direct access to specific areas in memory or to the stack to speed up their programs. When the OS changes - like to Vista - the memory maps and stacks change, and all of a sudden things crash.

Unfortunately, I'm not an expert - I'm an embedded firmware guy - so I can't tell you how to do it.

Re: OT - Question for programmers

#6

Re: OT - Question for programmers

Bill Howatt

>Probably best to ask this question on one of the MS developer forums.

While us old guys remember the good old days of doing DMA into physical locations many modern OSs want to you to go through the proper mechanisms to avoid problems with programs attempting to overwrite space reserved by another program. If the OS doesn't know what is happening to its resources then all heck breaks loose. This provides much better safety and stability but unfortunately raises the amount of overhead and time to do the transfer, particularly in the setup phase.

Wish I could be of more help,

Bill

Re: OT - Question for programmers

#7

Re: OT - Question for programmers

Dave Arbuckle, Plano, TX

>Normally, no. Here's a program that represents that it can change Windows' permissions to enable direct access to memory: http://www.vsres.com/activeport/

Why anyone wants all the hilarity of trying to maintain compatibility by doing that escapes. It's 2008, time to give up on techniques obsolete in 1990. ;-)

Re: OT - Question for programmers

#8

Thanks all

Denis Ch�nard, Orl�ans, Ont.

>I think understand the process better now. Our application is written in ANSI C and doesn't need direct access to I/O, but by writing directly to memory we save a lot of overhead. It is run from a Linux console, so there's no graphical output or anything fancy. All we want is to churn a mountain of data in the fastest way possible (a run generates about 10 GB of output).

Thanks again,

DC

Re: OT - Question for programmers

#9

ebd

Re: OT - Question for programmers

ebd

>I'd like to see you do it without generating at least a memory exception error. You've got to be way deep and ultra hidden, and even then you're more likely to F _ _ _ things up than accomplish what you want.

Re: OT - Question for programmers

#10

You mean like PEEK and POKE?

Mark Goodall - ATL - tooljunkie

>"...It's 2008, time to give up on techniques obsolete in 1990. ;-)

...

You mean like PEEK and POKE :)

No wait, that was obsolete in the 80's ;)

Happy Woodworking!

Re: OT - Question for programmers

#11

Re: The reason you don't do that

Peter Gregory

>is because you compiler should do a better job accessing memory, than your programmers. Kind of like writing inline assembler code, don't do it.

Re: OT - Question for programmers

#12

Easiest way

Mark Goodall - ATL - tooljunkie

>The easies way to speed up a program...... is to get a faster CPU ;)

Seriously..... a faster CPU is often much less expensive than tricky programming these days.

Happy Woodworking!

Re: OT - Question for programmers

#13

Easiest way is the road to ....

John K Jordan

>>a faster CPU is often much less expensive than tricky programming these days.

Unfortunately, Microsoft and most other developers learned that lesson long ago. Witness the repeated release of obscenely bloated, inefficient, legacy code patched and "enhanced" with a glut of new features and bugs at a schedule carefully calculated to get you to part with upgrade dollars. Why pay wizards to write robust and efficient code when the sluggishness of the latest software cesspool release will be disguised by faster hardware? And since the bloat is in the OS, there is no escape even for efficient programs.

As one example: after a long absence from programming I installed a recent MS development system. Although this computer is at least 10 times faster, both the interface and the complier run slower than it's predecessor did years ago.

Don't get me started. Wait, I've already started!

JKJ