EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Basic memory question CBFS

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#5377
Posted: 03/13/2008 00:47:37
by adam  (Basic support level)
Joined: 03/13/2008
Posts: 18

I have a very basic question

Do the the events i write in an .net C# program for CBFS run in managed memory ? if so is that why in the samples GCHandle is used to access parameters passed form the (cbfs driver)) in unmanaged memory.

Or do the .net events run in unmanaged memory ? and GCHandle is used to access .net parameters in the cbds driver?

Thanks in advance

P.S. would anyone recommend any tutorials on working with unmanaged memory from .net?
#5411
Posted: 03/13/2008 13:09:56
by Eugene Mayevski (EldoS Corp.)

The events have IntPtr parameter. The event handlers cast IntPtr to GCHandle and back to access the data.

IntPtr was chosen because the contexts are kept in unmanaged memory and IntPtr is a convenient way to manage objects and primitive types, giving you possibility to keep both objects and primitive types like Integer (int) or arrays.

This is covered in help file in more details (and with examples) here

There are some internal operations with unmanaged buffers, but they are used in calls to unmanaged WinAPI functions. These operations are not directly related to CBFS.

Your event handlers are executed in managed mode, but they are free to use both managed and unmanaged memory (as shown in the sample project).


Sincerely yours
Eugene Mayevski
#5417
Posted: 03/13/2008 18:57:50
by adam  (Basic support level)
Joined: 03/13/2008
Posts: 18

Why are contexts stored in unmanaged memory?
#5421
Posted: 03/14/2008 00:23:37
by Eugene Mayevski (EldoS Corp.)

Because this was designed so. Sorry, we don't discuss design decisions.


Sincerely yours
Eugene Mayevski
#5473
Posted: 03/17/2008 21:23:20
by adam  (Basic support level)
Joined: 03/13/2008
Posts: 18

Are fileContexts passed between the CBFS driver and User mode application events in the fucntion paramaters to encapsulate the data ?

Is it possible to set the values of the application contexts pointer to IntPtr.Zero and use a global varable insted?

for example

[code]
GlobalFileContext[] gFileCont;

private void CbFsOpenFile(object sender, string FileName, uint FileAttributes, ref IntPtr FileHandleContext)
{
FileHandleContext = IntPtr.Zero;

gFileCont[x] = new GlobalFileContext();
............
}

private void CbFsReadFile(
CallbackFileSystem sender,
CbFsFileInfo FileInfo,
IntPtr FileHandleContext,
long Position,
byte[] Buffer,
int BytesToRead,
ref int BytesRead
)
{

FileStream fs = gFileCont[x].hStream;

.............
}

[code]
#5480
Posted: 03/18/2008 03:07:36
by Volodymyr Zinin (EldoS Corp.)

You can. But it isn't necessary to do. Because the FileHandleContext parameter was designed for this.
And be sure that for all OnOpen requests there are respective OnClose requests. So you can safely use FileHandleContext to save necessary information associated with the opened file.
Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.

Reply

Statistics

Topic viewed 4507 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!