For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > November 2005 > Is it possible to do that in vb?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Is it possible to do that in vb?
Jack

2005-11-26, 6:55 pm

What I need is to reserve part of memory (not a space on harddrive) to
collect some data by my app.
Next, AFTER closing my app. I would like to access that data by some how and
store it to the file.
How to achieve that?

I know, I can access that memory before my app. closes and save that data to
file and in fact my app does that.
The problem is that my app is a testing hardware application and sometimes
it causes some errors and Windows closes it down forcefully and data is not
saved.
Maybe should I have 2 apps running simultaneously and send data that way?
Your thoughts deeply appreciated,
Jack


MikeD

2005-11-26, 6:55 pm


"Jack" <replyto@newsgroup> wrote in message
news:ez1xZ0t8FHA.3804@TK2MSFTNGP14.phx.gbl...
> What I need is to reserve part of memory (not a space on harddrive) to
> collect some data by my app.
> Next, AFTER closing my app. I would like to access that data by some how
> and store it to the file.
> How to achieve that?


Not possible. No app can "reserve" RAM when it's not running (unless you
count memory leaks).

>
> I know, I can access that memory before my app. closes and save that data
> to file and in fact my app does that.
> The problem is that my app is a testing hardware application and sometimes
> it causes some errors and Windows closes it down forcefully and data is
> not saved.


Then you need to re-write your app so that it's not leaving files open. Open
the file only when you need to write data and then immediately close the
file after the data is written. Otherwise, you're just going to have to live
with the data loss.

It sounds as if you're only saving to a file when the app is closed. If
your app is constantly writing data (perhaps because it's continually
logging test results), then constantly opening/closing the file might not be
practicle. In that case, the only thing I can suggest is automatically save
the file on a fairly regular basis (maybe every few seconds or so; you'd
need to determine how often) to at least minimize data loss.

--
Mike
Microsoft MVP Visual Basic


Jack

2005-11-26, 6:55 pm

Thank you, Mike.
How about the other suggestion?
Sending data to the parallel application?
Can that application be spanned by the primary application or it must be the
independent one?
Jack
"MikeD" <nobody@nowhere.edu> wrote in message
news:ObBkBNu8FHA.2816@tk2msftngp13.phx.gbl...
>
> "Jack" <replyto@newsgroup> wrote in message
> news:ez1xZ0t8FHA.3804@TK2MSFTNGP14.phx.gbl...
>
> Not possible. No app can "reserve" RAM when it's not running (unless you
> count memory leaks).
>
>
> Then you need to re-write your app so that it's not leaving files open.
> Open the file only when you need to write data and then immediately close
> the file after the data is written. Otherwise, you're just going to have
> to live with the data loss.
>
> It sounds as if you're only saving to a file when the app is closed. If
> your app is constantly writing data (perhaps because it's continually
> logging test results), then constantly opening/closing the file might not
> be practicle. In that case, the only thing I can suggest is automatically
> save the file on a fairly regular basis (maybe every few seconds or so;
> you'd need to determine how often) to at least minimize data loss.
>
> --
> Mike
> Microsoft MVP Visual Basic
>
>



Dmitriy Antonov

2005-11-27, 3:55 am


"Jack" <replyto@newsgroup> wrote in message
news:%23DwJ5Uu8FHA.736@TK2MSFTNGP09.phx.gbl...[color=darkred]
> Thank you, Mike.
> How about the other suggestion?
> Sending data to the parallel application?
> Can that application be spanned by the primary application or it must be
> the independent one?
> Jack
> "MikeD" <nobody@nowhere.edu> wrote in message
> news:ObBkBNu8FHA.2816@tk2msftngp13.phx.gbl...

I am sure you can find solution without using external application.

If for any reason you still need such application, then you could use
out-of-process server (ActiveX.exe). In this case one of possible solutions
could be a class within that Activex.exe, which will encapsulate all I/O
operations, including opening and closing the file and writing data to it.
You will explicitly open the file and periodically write data to that file.
During normal application shut down and right before it the application will
explicitly close the file via call to corresponding method of that class.
Otherwise, after abnormal end, COM rules will enforce your component to shut
down after some period of time (I think it is something like 2 minutes), if
no external references exist and no visible elements on the screen, and the
class, in its Terminate event, will close the file if it is still open. This
will ensure that file is always properly closed and any cached data is saved
to disk.

Since out-of-process server has its own process, the crash of the main
application will not lead to the crash of the component.

Dmitriy.



Andre Kaufmann

2005-11-27, 3:55 am

Jack wrote:
> What I need is to reserve part of memory (not a space on harddrive) to
> collect some data by my app.
> Next, AFTER closing my app. I would like to access that data by some how and
> store it to the file.
> How to achieve that?


I think you're searching for memory mapped files. You may map a file to
memory and all changes in the memory are automatically written to the
file, even if your application crashes.
Other applications may access the memory / file in the same way parallel
/ before or after your application has terminated.

> [...]
> Jack


Andre
Jack

2005-11-27, 6:55 pm

Thank you.
Never before heard that.
Something new to learn :)
I think it is what I need . Thanks.
Jack
"Andre Kaufmann" <andre.kaufmann.bei@t-online.de> wrote in message
news:%230OCGXz8FHA.132@TK2MSFTNGP15.phx.gbl...
> Jack wrote:
>
> I think you're searching for memory mapped files. You may map a file to
> memory and all changes in the memory are automatically written to the
> file, even if your application crashes.
> Other applications may access the memory / file in the same way parallel /
> before or after your application has terminated.
>
>
> Andre



Karl E. Peterson

2005-11-29, 6:55 pm

Jack wrote:
> Thank you.
> Never before heard that.
> Something new to learn :)
> I think it is what I need . Thanks.


I think so, too.

Example: http://vb.mvps.org/samples/MapFile
--
Working without a .NET?
http://classicvb.org/


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com