HighTechTalks DotNet Forums  

How To Avoids CLR GC operation

Dotnet Framework (CLR) microsoft.public.dotnet.framework.clr


Discuss How To Avoids CLR GC operation in the Dotnet Framework (CLR) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
elwolv
 
Posts: n/a

Default How To Avoids CLR GC operation - 12-03-2007 , 01:15 PM






Hello;

I am trying to write a c# .net code where no GC un-timed memory operation.
the purpose of which is to allow the code to be responsive in real time as
possible.

what are the steps to talk in selecting type of objects and variable.
do we use a single class for the program?
how to make all structures and variables persistence not subject to GC?
what makes a method or functions persistence not subject to GC?

thank you

--
elwolv

Reply With Quote
  #2  
Old   
Chris Mullins [MVP - C#]
 
Posts: n/a

Default Re: How To Avoids CLR GC operation - 12-03-2007 , 02:03 PM






The construct you're looking for is called a Constrained Execution Region.
It's not quite what you want, but it's likley very close.

Documentation:
http://msdn2.microsoft.com/en-us/library/ms228973.aspx

MSDN Article on the topic:
http://msdn.microsoft.com/msdnmag/is...y/default.aspx


.... Note: This isn't suitable for an entire application, but rather regions
of code. If that's your goal, you should use C++ or Delphi, as a managed
language (.Net, Java) isn't going to cut it.

--
Chris Mullins

"elwolv" <elwolv (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hello;

I am trying to write a c# .net code where no GC un-timed memory operation.
the purpose of which is to allow the code to be responsive in real time as
possible.

what are the steps to talk in selecting type of objects and variable.
do we use a single class for the program?
how to make all structures and variables persistence not subject to GC?
what makes a method or functions persistence not subject to GC?

thank you

--
elwolv



Reply With Quote
  #3  
Old   
elwolv
 
Posts: n/a

Default Re: How To Avoids CLR GC operation - 12-03-2007 , 04:56 PM



Hello;

thank you for your reply.

I understand your comment.
gc can not be disabled
and c# managed clr will kick in when it is become needed (out of my control)
and .net can not be made real time response

restate my question:

there are structures that is persistence in memory and GC does not collect
and remove.

what is would be recommended to use such structures in simple c# program to
make gc has no need to collect memory, if all the objects are persistence?

thank you
--
elwolv


"Chris Mullins [MVP - C#]" wrote:

Quote:
The construct you're looking for is called a Constrained Execution Region.
It's not quite what you want, but it's likley very close.

Documentation:
http://msdn2.microsoft.com/en-us/library/ms228973.aspx

MSDN Article on the topic:
http://msdn.microsoft.com/msdnmag/is...y/default.aspx


.... Note: This isn't suitable for an entire application, but rather regions
of code. If that's your goal, you should use C++ or Delphi, as a managed
language (.Net, Java) isn't going to cut it.

--
Chris Mullins

"elwolv" <elwolv (AT) discussions (DOT) microsoft.com> wrote in message
news:F985B6ED-4E0A-4557-9A04-FD967DA9AC54 (AT) microsoft (DOT) com...
Hello;

I am trying to write a c# .net code where no GC un-timed memory operation.
the purpose of which is to allow the code to be responsive in real time as
possible.

what are the steps to talk in selecting type of objects and variable.
do we use a single class for the program?
how to make all structures and variables persistence not subject to GC?
what makes a method or functions persistence not subject to GC?

thank you

--
elwolv




Reply With Quote
  #4  
Old   
Chris Mullins [MVP - C#]
 
Posts: n/a

Default Re: How To Avoids CLR GC operation - 12-03-2007 , 06:20 PM



The question is easy to answer: Make the Static. This will put them on the
high frequency heap, and they won't ever be collected.

.... now, with that said, this is probably pretty silly. What are you
building that you think GC will just wreck?

Given you level of knowledge about .Net, I would guess you haven't tried any
of this yet, and are shooting in the dark. If this is the case, you may want
to step back and take a bigger look at things.

Figure out your performance and latency requirements, and from there
determine if you can use .Net or not.

In the best case, you're guilty of waaaaay premature optimization, and
you're going to make things worse rather than better.

--
Chris Mullins


"elwolv" <elwolv (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hello;

thank you for your reply.

I understand your comment.
gc can not be disabled
and c# managed clr will kick in when it is become needed (out of my
control)
and .net can not be made real time response

restate my question:

there are structures that is persistence in memory and GC does not collect
and remove.

what is would be recommended to use such structures in simple c# program
to
make gc has no need to collect memory, if all the objects are persistence?

thank you
--
elwolv


"Chris Mullins [MVP - C#]" wrote:

The construct you're looking for is called a Constrained Execution
Region.
It's not quite what you want, but it's likley very close.

Documentation:
http://msdn2.microsoft.com/en-us/library/ms228973.aspx

MSDN Article on the topic:
http://msdn.microsoft.com/msdnmag/is...y/default.aspx


.... Note: This isn't suitable for an entire application, but rather
regions
of code. If that's your goal, you should use C++ or Delphi, as a managed
language (.Net, Java) isn't going to cut it.

--
Chris Mullins

"elwolv" <elwolv (AT) discussions (DOT) microsoft.com> wrote in message
news:F985B6ED-4E0A-4557-9A04-FD967DA9AC54 (AT) microsoft (DOT) com...
Hello;

I am trying to write a c# .net code where no GC un-timed memory
operation.
the purpose of which is to allow the code to be responsive in real time
as
possible.

what are the steps to talk in selecting type of objects and variable.
do we use a single class for the program?
how to make all structures and variables persistence not subject to GC?
what makes a method or functions persistence not subject to GC?

thank you

--
elwolv






Reply With Quote
  #5  
Old   
elwolv
 
Posts: n/a

Default Re: How To Avoids CLR GC operation - 12-04-2007 , 11:30 AM



hello;

thank you for your response.

I am trying to use .met MF to issue motor control commands
commands can't be delayed for GC action.
Since GC is the system in .net MF it is the one who use/steals cycles from
the cpu.
By using static we can help continuous stream of commands without any
un-timed GC latency.

yes; .net MF/XP are not real time system and only windows CE/Linux are real
time OS.,
However, .net MF CLR is the OS to be concern on the system.

my question now would be:

1- is there any specific technique for CLR (known to you as more
knowledgeable) to be used in this manner to help keep the commands flow
without interruption?
2- short of using real time OS, I want to use .net MF; because it is easy to
use and less time consuming and is really a good way to use embedded MCU.
then what is the best ways to do that with the understanding, that we can't
make .net MF a complete zero latency? there is enough RAM to hold a program.

thank you


--
elwolv


"Chris Mullins [MVP - C#]" wrote:

Quote:
The question is easy to answer: Make the Static. This will put them on the
high frequency heap, and they won't ever be collected.

.... now, with that said, this is probably pretty silly. What are you
building that you think GC will just wreck?

Given you level of knowledge about .Net, I would guess you haven't tried any
of this yet, and are shooting in the dark. If this is the case, you may want
to step back and take a bigger look at things.

Figure out your performance and latency requirements, and from there
determine if you can use .Net or not.

In the best case, you're guilty of waaaaay premature optimization, and
you're going to make things worse rather than better.

--
Chris Mullins


"elwolv" <elwolv (AT) discussions (DOT) microsoft.com> wrote in message
news8AC3945-1FEE-4D4F-87C1-AF0B5D3A9044 (AT) microsoft (DOT) com...
Hello;

thank you for your reply.

I understand your comment.
gc can not be disabled
and c# managed clr will kick in when it is become needed (out of my
control)
and .net can not be made real time response

restate my question:

there are structures that is persistence in memory and GC does not collect
and remove.

what is would be recommended to use such structures in simple c# program
to
make gc has no need to collect memory, if all the objects are persistence?

thank you
--
elwolv


"Chris Mullins [MVP - C#]" wrote:

The construct you're looking for is called a Constrained Execution
Region.
It's not quite what you want, but it's likley very close.

Documentation:
http://msdn2.microsoft.com/en-us/library/ms228973.aspx

MSDN Article on the topic:
http://msdn.microsoft.com/msdnmag/is...y/default.aspx


.... Note: This isn't suitable for an entire application, but rather
regions
of code. If that's your goal, you should use C++ or Delphi, as a managed
language (.Net, Java) isn't going to cut it.

--
Chris Mullins

"elwolv" <elwolv (AT) discussions (DOT) microsoft.com> wrote in message
news:F985B6ED-4E0A-4557-9A04-FD967DA9AC54 (AT) microsoft (DOT) com...
Hello;

I am trying to write a c# .net code where no GC un-timed memory
operation.
the purpose of which is to allow the code to be responsive in real time
as
possible.

what are the steps to talk in selecting type of objects and variable.
do we use a single class for the program?
how to make all structures and variables persistence not subject to GC?
what makes a method or functions persistence not subject to GC?

thank you

--
elwolv







Reply With Quote
  #6  
Old   
Chris Mullins [MVP - C#]
 
Posts: n/a

Default Re: How To Avoids CLR GC operation - 12-04-2007 , 11:51 AM



You're up against a target I don't think you're going to hit based on advice
from a newsgroup.

Go out, write some prototype code, and get it running. When it doesn't work,
keep trying various approaches until you get something you like.

I suspect you're going to get the compact framework, running on a mobile
device, to work as well as you're hoping. I would like to be wrong, but
based on my work with the Compact Framework, you've got an uphill battle on
your hands. I suspect GC will be one of your concerns, but will be far from
the last...

--
Chris Mullins

"elwolv" <elwolv (AT) discussions (DOT) microsoft.com> wrote

Quote:
hello;

thank you for your response.

I am trying to use .met MF to issue motor control commands
commands can't be delayed for GC action.
Since GC is the system in .net MF it is the one who use/steals cycles from
the cpu.
By using static we can help continuous stream of commands without any
un-timed GC latency.

yes; .net MF/XP are not real time system and only windows CE/Linux are
real
time OS.,
However, .net MF CLR is the OS to be concern on the system.

my question now would be:

1- is there any specific technique for CLR (known to you as more
knowledgeable) to be used in this manner to help keep the commands flow
without interruption?
2- short of using real time OS, I want to use .net MF; because it is easy
to
use and less time consuming and is really a good way to use embedded MCU.
then what is the best ways to do that with the understanding, that we
can't
make .net MF a complete zero latency? there is enough RAM to hold a
program.

thank you


--
elwolv


"Chris Mullins [MVP - C#]" wrote:

The question is easy to answer: Make the Static. This will put them on
the
high frequency heap, and they won't ever be collected.

.... now, with that said, this is probably pretty silly. What are you
building that you think GC will just wreck?

Given you level of knowledge about .Net, I would guess you haven't tried
any
of this yet, and are shooting in the dark. If this is the case, you may
want
to step back and take a bigger look at things.

Figure out your performance and latency requirements, and from there
determine if you can use .Net or not.

In the best case, you're guilty of waaaaay premature optimization, and
you're going to make things worse rather than better.

--
Chris Mullins


"elwolv" <elwolv (AT) discussions (DOT) microsoft.com> wrote in message
news8AC3945-1FEE-4D4F-87C1-AF0B5D3A9044 (AT) microsoft (DOT) com...
Hello;

thank you for your reply.

I understand your comment.
gc can not be disabled
and c# managed clr will kick in when it is become needed (out of my
control)
and .net can not be made real time response

restate my question:

there are structures that is persistence in memory and GC does not
collect
and remove.

what is would be recommended to use such structures in simple c#
program
to
make gc has no need to collect memory, if all the objects are
persistence?

thank you
--
elwolv


"Chris Mullins [MVP - C#]" wrote:

The construct you're looking for is called a Constrained Execution
Region.
It's not quite what you want, but it's likley very close.

Documentation:
http://msdn2.microsoft.com/en-us/library/ms228973.aspx

MSDN Article on the topic:
http://msdn.microsoft.com/msdnmag/is...y/default.aspx


.... Note: This isn't suitable for an entire application, but rather
regions
of code. If that's your goal, you should use C++ or Delphi, as a
managed
language (.Net, Java) isn't going to cut it.

--
Chris Mullins

"elwolv" <elwolv (AT) discussions (DOT) microsoft.com> wrote in message
news:F985B6ED-4E0A-4557-9A04-FD967DA9AC54 (AT) microsoft (DOT) com...
Hello;

I am trying to write a c# .net code where no GC un-timed memory
operation.
the purpose of which is to allow the code to be responsive in real
time
as
possible.

what are the steps to talk in selecting type of objects and
variable.
do we use a single class for the program?
how to make all structures and variables persistence not subject to
GC?
what makes a method or functions persistence not subject to GC?

thank you

--
elwolv









Reply With Quote
  #7  
Old   
Ben Voigt [C++ MVP]
 
Posts: n/a

Default Re: How To Avoids CLR GC operation - 12-04-2007 , 12:47 PM




"elwolv" <elwolv (AT) discussions (DOT) microsoft.com> wrote

Quote:
hello;

thank you for your response.

I am trying to use .met MF to issue motor control commands
commands can't be delayed for GC action.
Since GC is the system in .net MF it is the one who use/steals cycles from
the cpu.
By using static we can help continuous stream of commands without any
un-timed GC latency.
By eliminating allocations (after startup) I think you should be able to
prevent the GC from running.

To do that, you'll need to pool your objects. I think you can use
LinkedList<T> for that as long as you save the LinkedListNode<T> and simply
move it between free and busy lists, always use the methods that take a
LinkedListNode because the only will allocate them.

Also, I hope you aren't doing any string manipulation, because strings can't
be pooled (they are immutable, so the only way to get a new value is to
allocate one). Use byte or character arrays instead of strings.

If you weren't on MF (where there is no interop layer) I'd say use C or C++
to create a native thread for the realtime operations, and pass buffers back
and forth to the managed thread, then don't worry about the GC.

Quote:
yes; .net MF/XP are not real time system and only windows CE/Linux are
real
time OS.,
However, .net MF CLR is the OS to be concern on the system.

my question now would be:

1- is there any specific technique for CLR (known to you as more
knowledgeable) to be used in this manner to help keep the commands flow
without interruption?
2- short of using real time OS, I want to use .net MF; because it is easy
to
use and less time consuming and is really a good way to use embedded MCU.
then what is the best ways to do that with the understanding, that we
can't
make .net MF a complete zero latency? there is enough RAM to hold a
program.

thank you


--
elwolv


"Chris Mullins [MVP - C#]" wrote:

The question is easy to answer: Make the Static. This will put them on
the
high frequency heap, and they won't ever be collected.

.... now, with that said, this is probably pretty silly. What are you
building that you think GC will just wreck?

Given you level of knowledge about .Net, I would guess you haven't tried
any
of this yet, and are shooting in the dark. If this is the case, you may
want
to step back and take a bigger look at things.

Figure out your performance and latency requirements, and from there
determine if you can use .Net or not.

In the best case, you're guilty of waaaaay premature optimization, and
you're going to make things worse rather than better.

--
Chris Mullins


"elwolv" <elwolv (AT) discussions (DOT) microsoft.com> wrote in message
news8AC3945-1FEE-4D4F-87C1-AF0B5D3A9044 (AT) microsoft (DOT) com...
Hello;

thank you for your reply.

I understand your comment.
gc can not be disabled
and c# managed clr will kick in when it is become needed (out of my
control)
and .net can not be made real time response

restate my question:

there are structures that is persistence in memory and GC does not
collect
and remove.

what is would be recommended to use such structures in simple c#
program
to
make gc has no need to collect memory, if all the objects are
persistence?

thank you
--
elwolv


"Chris Mullins [MVP - C#]" wrote:

The construct you're looking for is called a Constrained Execution
Region.
It's not quite what you want, but it's likley very close.

Documentation:
http://msdn2.microsoft.com/en-us/library/ms228973.aspx

MSDN Article on the topic:
http://msdn.microsoft.com/msdnmag/is...y/default.aspx


.... Note: This isn't suitable for an entire application, but rather
regions
of code. If that's your goal, you should use C++ or Delphi, as a
managed
language (.Net, Java) isn't going to cut it.

--
Chris Mullins

"elwolv" <elwolv (AT) discussions (DOT) microsoft.com> wrote in message
news:F985B6ED-4E0A-4557-9A04-FD967DA9AC54 (AT) microsoft (DOT) com...
Hello;

I am trying to write a c# .net code where no GC un-timed memory
operation.
the purpose of which is to allow the code to be responsive in real
time
as
possible.

what are the steps to talk in selecting type of objects and
variable.
do we use a single class for the program?
how to make all structures and variables persistence not subject to
GC?
what makes a method or functions persistence not subject to GC?

thank you

--
elwolv









Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.