EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Basic memory question CBFS

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?
Posted: 03/13/2008 13:09:56
by Eugene Mayevski (Team)

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
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?
Posted: 03/14/2008 00:23:37
by Eugene Mayevski (Team)

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

Sincerely yours
Eugene Mayevski
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

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;


Posted: 03/18/2008 03:07:36
by Volodymyr Zinin (Team)

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.



Topic viewed 7389 times

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


Back to top

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

Got it!