Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / May 2006

Tip: Looking for answers? Try searching our database.

Unmaged Code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TARUN - 11 May 2006 07:05 GMT
Hello All

I need to sak one question related to the CLR and Managed And Unmanage
Code

I read in the MSDN that .....
The code which is targetting CLR is managed code.
The code which is not targetting CLR is unmanaged code
Unmanged Code Means which directly interact with OS functionalty.

If this concept is correct then i need to verify with the reason  that
, the statement
"usage of  Pointer in application mean that this code is unmanaged
code" is true or false
What??

with regards
tarun sinha
Göran Andersson - 11 May 2006 07:35 GMT
False.

You have to use an unsafe context to use pointers in managed code, but
that doesn't make it unmanaged.

> Hello All
>
[quoted text clipped - 14 lines]
> with regards
> tarun sinha
TARUN - 11 May 2006 11:39 GMT
I didn't understand the word unsafe context .... can ou Please explain
me  abit
Göran Andersson - 11 May 2006 13:31 GMT
Example:

byte[] twoBytes;
byte byteOne, byteTwo;

twoBytes = new byte[] { 1, 2 };
unsafe {
   byte* ptr = &(asdf[0]);
   byteOne = *ptr;
   ptr++;
   byteTwo = *ptr;
}

> I didn't understand the word unsafe context .... can ou Please explain
> me  abit
TARUN - 11 May 2006 14:35 GMT
Thanks  for repling me so soon ...

if we using the pointer .that mean .we are dealing with unmange Code
Can you suggest me manged Code using Pointer . Is it Possible ???
"I mean I want to Know existance of pointer in code make it unmanaged "
Is this statement is true or false and why Please tell me the reason???

Thank You
With regards
tarun sinha
Göran Andersson - 11 May 2006 15:08 GMT
> Thanks  for repling me so soon ...
>
>  if we using the pointer .that mean .we are dealing with unmange Code

No.

> Can you suggest me manged Code using Pointer . Is it Possible ???

Look at the code in my previous post.

> "I mean I want to Know existance of pointer in code make it unmanaged "
> Is this statement is true or false

I already answered this in my first reply.

> and why Please tell me the reason???

As for the reason: Why in the world would it make it unmanaged?

It's obvious that you don't know the difference between managed and
unmanaged code. Google some and read up on the basic principles of
managed code.
Ole Nielsby - 11 May 2006 17:53 GMT
> Thanks  for repling me so soon ...
>
> if we using the pointer .that mean .we are dealing with unmange Code
> Can you suggest me manged Code using Pointer . Is it Possible ???

There are two things that can be managed/unmanaged:
data and code.

Managed code means, the compiler produces il instructions
instead of raw machine code. When the program runs, the
clr will compile the il to machine code as needed.

Managed data means, you let the clr handle memory allocations
and deallocations. The clr will sometimes move your data behind
the scenes, so you generally can't trust pointers.

The C# and VB.NET compilers always produce managed code
that ususally works with managed data. However C# allows
limited use of unmanaged data.

With C++, you can produce managed code that works with
a mix of managed and unmanaged data. Or you can produce
unmanaged code that works with unmanaged data. Unmanaged
code should not access managed data, except through COM
interop or similar techniques.

Hope this clears things up a bit. If not, just stay with the
managed stuff and forget about pointers.

ON
TARUN - 12 May 2006 06:47 GMT
you explain me but still i am in confusion of unmanged code and data.
In a previous post you mention the statement "The clr will sometimes
move your data behind
the scenes"
Please explain Further the above statement.
One More thing sir, can you Please define unmanaged code and data in
the similar way as you define manged code and data.

Thank You
With regards
Tarun Sinha
Ole Nielsby - 13 May 2006 00:10 GMT
> you explain me but still i am in confusion of unmanged code and data.
> In a previous post you mention the statement "The clr will sometimes
> move your data behind the scenes"
> Please explain Further the above statement.

It's called compacting garbage collection. At unpredictable times,
the clr will pause the execution of managed code and defragment
memory by moving managed objects. Generally, you don't need
to care about this unless you use pointers with managed objects.
If you really need pointers into managed objects, you need to pin
the objects. But don't unless you really have to.

> One More thing sir, can you Please define unmanaged code
> and data in the similar way as you define manged code and
> data.

"Unmanaged" simply means, it's not controlled or defined by
the clr. A discussion of unmanaged code and data is really
outside the scope of this newsgroup.
Tasos Vogiatzoglou - 16 May 2006 14:38 GMT
The "usual" (unmanaged code) is produced by a compiler and it is
immediatelly available to the CPU for running. This means that a
program in unmanaged code is essentially a group of CPU instructions.

Managed code is a "intermediate" state of code where you need an
additional layer (virtual machine) in order to translate managed code
to pure CPU instructions (that the CPU can understand).

Garbage collection is not something particular to managed code. Managed
code has to do with the need of an intermediate layer in order to
execute it. This "intermediate layer" usually provides additional
services like memory reclaiming mechanism, just in time compilers etc
etc

Pointer can be used in both managed/unmanaged code. The only difference
is that the CLR (the .NET virtual machine) forces you to do this in an
unsafe context. By saying unsafe that means that the pointer can show
anywhere you like (and potentialy do something wrong). There is the
IntPtr class in .net where you can use pointers outside of an unsafe
context although in a limited fashion.

Best regards,
Tasos

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.