FoxPro Programming
Load Binary Direct From Memory
Gravatar is a globally recognized avatar based on your email address. Load Binary Direct From Memory
  John
  All
  Dec 26, 2018 @ 04:33pm

Hi, Rick I'm John from Greece. I sent you a email for some help and you tell me to posted here, so I will explain by problem with more detail. The basic idea here is to update code while a system is running. So a simple scenario...

I create a prg file with a simple class (DEFINE CLASS... ENDDEFINE) in VFP IDE. From command window I compile the file and I upload the fxp file to a web server. Then suppose that my client has an executable. When he/she runs the exe, the exe make a request to my server and get the fxp file let's say to response text property. I don't save it to file! So I have the binary code (fxp) ready to memory. So how can I use it without save to disk? I know the easy way is to save it to disk and perform a SET PROCEDURE TO with CreateObject or NewObject and create an instance of the class. But I feel so stupid because I have machine code to memory and I can't used it! It drive me crazy! Then I was trying to find out if the "SET PROCEDURE TO" command executes some win32api functions but I didn't find something. So do you have any idea? Thanks for your time.

Gravatar is a globally recognized avatar based on your email address. re: Load Binary Direct From Memory
  Tore Bleken
  John
  Dec 27, 2018 @ 01:02am

Can you give any good reason why you don' want to store the file on disk? I don't see any. Forget that idea, tore it in one of the temp folders, and delete it afterwards.

Gravatar is a globally recognized avatar based on your email address. re: Load Binary Direct From Memory
  John
  Tore Bleken
  Dec 27, 2018 @ 02:18am

As I said before ... "I know the easy way is to save it to disk and perform a SET PROCEDURE TO with CreateObject or NewObject and create an instance of the class."

A good reason for doing this, is that you can write 1GB of data in memory in few milliseconds but on hard disk about a minute. An other reason is that you have the binary to memory. It stupid to make useless rounds from memory to disk and from disk to memory. Also from the point of the development view is the curiosity and ideas that give us motivation. Forgeting ideas give us nothing. Thanks John

Gravatar is a globally recognized avatar based on your email address. re: Load Binary Direct From Memory
  Tore Bleken
  John
  Dec 27, 2018 @ 03:28am

I strongly disagree on your speed comparison. The slow part is downloading the file in question. Windows' disk cache will make a file on disk almost as fast as working from the computer's memory. Unless you have an extremely sloooow HD....

Gravatar is a globally recognized avatar based on your email address. re: Load Binary Direct From Memory
  John
  Tore Bleken
  Dec 27, 2018 @ 03:47am

In theory it is true. But if you measure it, it's not. Anyway the subject of my question is other than this. If you know something about how SET PROCEDURE TO works internal, which win32api functions calls, it will be heplful to me. Thanks John.

Gravatar is a globally recognized avatar based on your email address. re: Load Binary Direct From Memory
  Tore Bleken
  John
  Dec 27, 2018 @ 04:00am

No, I'm pretty sure that it's not possible, and that you are wasting your time.

Gravatar is a globally recognized avatar based on your email address. re: Load Binary Direct From Memory
  Rick Strahl
  John
  Dec 27, 2018 @ 12:46pm

It's not possible...

FoxPro's execution engine compiles only from disk and there's no mechanism available to compile from memory or some other programmatic stream through the language.

As Tore said the easy way to do this is to create a temp folder and dump the FXPs into there to execute. Note that the FXPs will be locked while something from within is loaded so you can't just delete them either. FoxPro loads and unloads code depending on memory and for this reason needs to continue to have access to the compiled code. The way to solve that is at the end of the application do CLOSE ALL RELEASE ALL etc. and then delete the FXP files, or do it on startup of the application rather than on shutdown.

FWIW if you're after dynamic execution of code that you want to store somewhere else like in a database, maybe use .NET code which can be loaded and executed from memory and call that from FoxPro.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Load Binary Direct From Memory
  Rick Strahl
  John
  Dec 27, 2018 @ 12:59pm

John,

Disk performance is very fast especially for something as small as a code file (no larger than 65k), in a locally accessed folder that is essentially cached in memory. And what could you possibly be doing with dynamically loading code that would make a real difference in performance in your application where the load time has an impact? You can't be loading more than a few files in this way and if you're doing it right you're hopefully only loading those files once and then reusing the code in them.

This is a good example of premature optimization - there are more pressing things that you can focus on to improve application performance.

Also a gigabyte a minute? Maybe you need to work with faster hardware... An SSD drive will write a gigabyte in a few seconds. Heck even transferring over USB from a GoPro camera is faster than a gig a minute.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Load Binary Direct From Memory
  John
  Rick Strahl
  Dec 27, 2018 @ 02:12pm

Hi Rick, Maybe you and I have fast SSD Disks. But users that use our programs possibly not (at least here in Greece). Everyday I see people using 10-15 years old machines with old heavy used hard disks. Anyway my idea was to eliminate the disk access but I will have many downloads. And this pain a lot. Maybe after all the disk with solve my problem for reusing fxp files. But I will have to make a versioning system in this files.

Thanks for your time. John

Gravatar is a globally recognized avatar based on your email address. re: Load Binary Direct From Memory
  Rick Strahl
  John
  Dec 28, 2018 @ 11:57am

Doesn't matter whether you have a slow hard disk or not. To save a 64k or less file takes milliseconds even on a very slow hard disk. The download by comparison will be thousands of times slower than the disk write.

Again - premature optimization...

IAC, the point is moot since it's not possible to execute from memory in FoxPro.

+++ Rick ---

© 1996-2019