|
Hi All;
Tnx for the input(s) everyone.
I shall (try to) work around by working on individual bits. I will be creating byte[] and work on individual bytes. I will work out true or false depending on the value of the bit at a particular address.
Ian
No trees were killed in the creation of this message. However, many electrons were terribly inconvenienced.
|
|
|
|
|
I managed to do it this way. I created a class to do the work of mapping the bits inside a byte array and will post a short article soon.
Tnx to everyone.
Ian
No trees were killed in the creation of this message. However, many electrons were terribly inconvenienced.
|
|
|
|
|
Article here[^].
No trees were killed in the creation of this message. However, many electrons were terribly inconvenienced.
|
|
|
|
|
Building a dictionary like this is going to be expensive. Why do you need to use a Dictionary? It looks like you could get by with a much simpler array:
bool[] _numbers = new bool[_Max];
for (int i = 0; i < _Max; i++)
_numbers[i] = true;
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
Hi Scott;
Tnx for the input.
Tried a bool array and I still get the same error.
Ian
No trees were killed in the creation of this message. However, many electrons were terribly inconvenienced.
|
|
|
|
|
Well you're still asking for 2 Gigs or RAM just from the booleans alone, so that's your problem.
|
|
|
|
|
I think your best option then is going to be to work with the individual bit values, as you mentioned in your other post[^].
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
hi
i write this code to generate a simple source code with CodeDom :
CodeCompileUnit compileUnit = new CodeCompileUnit();<br />
CodeNamespace ns = new CodeNamespace("MyNameSpace3");<br />
ns.Imports.Add(new CodeNamespaceImport("System"));<br />
ns.Imports.Add(new CodeNamespaceImport("System.Text"));<br />
CodeTypeDeclaration ctd = new CodeTypeDeclaration("MyClass3");<br />
ctd.IsClass = true;<br />
ns.Types.Add(ctd);<br />
compileUnit.Namespaces.Add(ns);<br />
<br />
CodeMemberField field1 = new CodeMemberField(typeof(string), "_message");<br />
field1.Attributes = MemberAttributes.Private; <br />
ctd.Members.Add(field1);<br />
<br />
CodeConstructor constructor1 = new CodeConstructor();<br />
constructor1.Attributes = MemberAttributes.Public;<br />
ctd.Members.Add(constructor1);
in above code, i have a private field (_message) in generated class code.
now i want to initialize and encapsulate that field with CodeDom, but how to do ?
thanks.
|
|
|
|
|
Hi, you need to use the CodeAssignStatement class to set a value for the _message field. Try this:
CodeAssignStatement fieldAssign = new CodeAssignStatement(
new CodeFieldReferenceExpression(
new CodeThisReferenceExpression(), "_message"),
new CodePrimitiveExpression("message value"));
constructor1.Statements.Add(fieldAssign);
Good luck (I think everyone needs a bit when using codeDom!)
Rob
"An eye for an eye only ends up making the whole world blind"
|
|
|
|
|
Hello,
I am trying to create a form filler program and came across a gap:
some of the sites's DOM fields simply can't be edited - for example:
https://login.bankhapoalim.co.il/cgi-bin/poalwwwc?&bank=414
the fields - "userid" and "id" can't be edited using the following code:
if (i_Webbrowser.LocationURL == "https://login.bankhapoalim.co.il/cgi-bin/poalwwwc?&bank=414")
{
HTMLInputElementClass input = GetInputElement("userid", i_Webbrowser);
input.value = "someValue";
}
does someone have any explanation/suggestions?
it is not the httpS issue since gmail fields can be filled.
thanks!!!
|
|
|
|
|
Help anyone?!?
|
|
|
|
|
Hello everyone,
Two conflicting points about how to implement Finalizer, which one is correct?
1.
I always heard from people that in Finalizer we should not refer to any other objects, since the order of Finalizer is non-determistic, means the referred object in Finalizer might not alive any more.
2.
From the following article from MSDN, seems we are safe to refer to any wrapped objects (in my understanding, it means referring to member variables in Finalizer is always safe)?
http://msdn2.microsoft.com/en-us/library/ms973837.aspx#dotnetgcbasics_topic2
--------------------
"How Finalization Affects Collection
When the garbage collector first encounters an object that is otherwise dead but still needs to be finalized it must abandon its attempt to reclaim the space for that object at that time. The object is instead added to a list of objects needing finalization and, furthermore, the collector must then ensure that all of the pointers within the object remain valid until finalization is complete.
....
Since the internal object pointers must remain valid, not only will the objects directly needing finalization linger in memory but everything the object refers to, directly and indirectly, will also remain in memory. If a huge tree of objects was anchored by a single object that required finalization, then the entire tree would linger, potentially for a long time as we just discussed."
--------------------
thanks in advance,
George
|
|
|
|
|
Not sure how you're making the jump from the quoted text to your second point...but...
1. The order of finalization is non-determistic, so there is no guarantee that if you access another object from within your finalizer that it will still be available.
2. If by "wrapped objects" you mean an object that your are internally maintaining, it is safe under certain circumstances.
Finalizers shouldn't do anything more than ensure that memory is cleaned up by calling the appropriate Dispose methods (or other means for unmanaged code). Almost all of the assumptions that can be made about the internal state of the .NET runtime (and your object) that would normally be valid are not when running in a finalizer.
What is it that you're trying to do that you think requires the use of a finalizer? In the large majority of cases, it isn't necessary to write one.
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
Scott's assessment is correct and in addition, in Microsoft's book CLR via CSharp[^] the advice given by the author is that a finalizer is used to ensure that native resources are released. And the only native resources that are mentioned in the text are Handles. So as I understand it, unless you are using items by their windows handles, don't bother. Highly recommend getting the book.
Scott P
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Cool, carbon_golem!
1.
One further question, if in my class, there is a StreamWriter data member, in the Finalizer method, if I do not close the StreamWriter, there should not be any resource leak, right? (because the Finalizer of StreamWriter itself will clean up native file handle resource wrapped by StreamWriter?)
2.
So, C# I/O class like StreamWriter is managed resource, not unmanaged resource?
regards,
George
|
|
|
|
|
George_George wrote: 1.
One further question, if in my class, there is a StreamWriter data member, in the Finalizer method, if I do not close the StreamWriter, there should not be any resource leak, right? (because the Finalizer of StreamWriter itself will clean up native file handle resource wrapped by StreamWriter?)
Fairly certain that's the case.
George_George wrote: 2.
So, C# I/O class like StreamWriter is managed resource, not unmanaged resource?
Yes.
Scott P
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Thanks carbon_golem,
I have made some further study.
http://msdn2.microsoft.com/en-us/library/ddae83kx.aspx
Seems that we can only access base.Finalize in Finalizer method of current class? Any comments? Please feel free to correct me if I am wrong.
--------------------
An object's Finalize method should not call a method on any objects other than that of its base class.
--------------------
regards,
George
|
|
|
|
|
That's right. The garbage collection can't guarantee that anything will be available - think of the case that your finalizer is the absolute last thing that is done in your application before it shuts down, all other resources have been reclaimed including all the members inside your class. That's what you have to deal with. The purpose of a finalizer is to give you one last chance to free any native resources that your class may use. One case is that you decide that you want a class with a Hook created by CreateWindowsHookEx and you own that hook. Finalizer implementation would be advised because you are using a native resource directly, and you don't want to leak that resource. As long as the finalizer exists, the runtime will call it, you don't need to. One special case is when you release the resource in your Dispose method, at then end of the Dispose, make a call to GC.SupressFinalize and the finalizer won't get called. Getting the idea?
If your class is using a built in .NET class that owns native resources, you can be pretty sure that .NET takes care of the finalizer for you. IF you implement a finalizer, the runtime calls it. The same holds true for the finalizers that .NET is using. Oh, one last thing, if you do decide to use a native resource by handle, look into .NET's SafeHandle classes, and that will shed some insight on what you're doing.
Again
1) If you implement a finalizer, the runtime will call it when it's being reclaimed by the garbage collector - UNLESS you have explicitly made a call to GC.SupressFinalize.
2) Implement a finalizer when you are using Native Resources, notably Handles.
3) You can never be sure what other data will be available when your finalizer is called.
4) Get Lutz's Reflector, and see how .NET does it's finalizers. I won't answer questions about Reflector, stfw.
Scott P
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Cool, Scott!
I agree with you in Finalizer we should only deal with releasing of native resource. I have got CLR via C# book, and referred the chapter 20, GC chapter. For the managed resource in Finalizer, it is suggested we only access the ones which do not have Finalizer method, because if there is finalizer method, the GC order of current object and referred object is not decided.
(section "Using Finalization with Managed Resources").
Do you agree or have any comments?
(So, our conclusion is, dealing with unmanaged resource and manged resource without Finalizer?)
regards,
George
|
|
|
|
|
That's it. Bravo.
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Thanks carbon_golem,
It is clear now.
regards,
George
|
|
|
|
|
Hi Scott,
Scott Dorman wrote: 1. The order of finalization is non-determistic, so there is no guarantee that if you access another object from within your finalizer that it will still be available.
2. If by "wrapped objects" you mean an object that your are internally maintaining, it is safe under certain circumstances.
The wrapped object I mean member variable of a class. From your above comments, I think your points are, it is not safe to access member variable of a class inside Finalizer method.
But from this link, it seems it is safe to access, since all the referred objects are retained live in Finalier. This why I am confused.
I think your points are conflicting with what I mentioned above and quoted below. Any comments?
http://msdn2.microsoft.com/en-us/library/ms973837.aspx#dotnetgcbasics_topic2[^]
--------------------
"How Finalization Affects Collection"
Since the internal object pointers must remain valid, not only will the objects directly needing finalization linger in memory but everything the object refers to, directly and indirectly, will also remain in memory. If a huge tree of objects was anchored by a single object that required finalization, then the entire tree would linger, potentially for a long time as we just discussed."
--------------------
regards,
George
|
|
|
|
|
I see your point and I think I understand where you are getting confused.
Even though the internal object pointers remain valid, there is still no guarantee that when you go to access them in the finalizer they will still be valid. From my article[^], Since finalizers run non-deterministically, there is no ordering among them so you can't rely on them being executing in a specific order. You should not access any finalizable objects your type may have a reference to because they may have already been finalized. As a result, you should only free unmanaged resources that your object owns.
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
Cool, Scott!
From learning in this forum, I think the best practice should be (also mentioned in the book CLR via C# version 2),
1. We can access and free unmanaged resource;
2. Base class Finalizer (code implicitly generarted);
3. Manages resource without Finalizer;
It is not safe to access,
Manages resource with Finalizer, since Finalizer execution order are non-determistic.
Any comments? Agree?
regards,
George
|
|
|
|
|
Glad you were able to get what you needed. I think that overall I would agree with those statements.
Thanks,
Scott.
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|