|
George_George wrote: 1.
I want to confirm that the answer to my question #3 is, C# is using constraints to check whether a type is supported or not, but C++ will generate the specific type to check whether the operation is supported or not, right?
Yes, the C++ compiler compiles the expanded template as part of the normal compilation mechanism.
George_George wrote: But from your sample below, I learned more. It seems C# compiler will check more than just the constraints, in your sample, without constraints, it will parse the invoked method to see whether it is supported, right?
Well, as part of compilation, it'll know that you called SayHello on the generic member, but it has no way of knowing whether the generic member has a SayHello. That's why it needs you to constrain the list of types that can be "substituted" for the generic member.
|
|
|
|
|
Thanks Senthil,
Question answered. You are so knowledgable and patience!
regards,
George
|
|
|
|
|
<br />
Name Size Value Desciption<br />
HEADER 4 bytes 0x04036b2e Mark this file as readable<br />
FILE_LEN 4 bytes Int32 Mark the length of FILE block<br />
FILE runtime byte[] The file's original name<br />
HASH 16 bytes byte[] Hash code of the data(header excluded)<br />
This is a simple header of a compressed file I'm developing. Each time a file is required to be processed, the program will firstly check the
header. If passed, compress the file and add header to it. The problem is, I have to firstly read the source file and create the output file,
and then compress it by using a third party method(the method will automatically close the input and output stream ), then open the output
file again, read it out to a buffer, write the header, and finally write the data in the buffer to the output file.
It's very inefficient . Is there any more efficient way to do this?
Thanks in advance...
modified on Sunday, May 11, 2008 4:52 AM
|
|
|
|
|
Does the method supplied for compression offer the chance to compress it in memory - ie pass it a stream that points to memory?
http://msdn.microsoft.com/en-us/library/336wast5.aspx.
If so you can use a StringReader/Writer if you wanted to work with strings or any other type of stream reader writer that takes your fancy. This should be faster than writing to disk then re-writing to disk with a header.
At university studying Software Engineering - if i say this line to girls i find they won't talk to me
Dan
|
|
|
|
|
Yes. It's defined as this:
<br />
public void Compress(Stream source, Stream target)<br />
But all the stream I passed to it will be closed. If I use memory stream, I won't be able to retrieve the compressed data.
|
|
|
|
|
If the stream points to a string then can you not use the string once the stream is closed and compressed. Then add the header added then write it to a file?
At university studying Software Engineering - if i say this line to girls i find they won't talk to me
Dan
|
|
|
|
|
Thanx Dan.
I'll have a try.
|
|
|
|
|
If the header has been generated before compressing, before pass the target stream into the compress method you can try writing the header into the target stream and set the stream's position at the end.
My english is very pool, i help i have said clearly.
|
|
|
|
|
thanx boblaw.
But the HASH is the hash code of the compressed data.
|
|
|
|
|
Your hash code is fixed in 16 bytes.
Firstly you can wirte 16 empty bytes into to stream before compressing. After you get the HASH, seek the stream'position at the first byte of 16 bytes and write hash code into it.
|
|
|
|
|
Thanks a lot.
But doing this will cause the header be compressed with the data.
|
|
|
|
|
My mean is you can write empty bytes into target stream before compressing, not source stream.
|
|
|
|
|
Sorry for misunderstanding....
I'll check it out whether the method will seek to the Begin and overwrite my header...
|
|
|
|
|
Hello everyone,
Two questions related to meta data and attribute,
1.
.Net built-in and user defined attribute are both defined in meta data portion of assembly or not? In my past experience, I think method/class level attribute is only used to facilitate the method/class IL generation, and will not exist in final assembly file. Any comments?
2.
If .Net built-in and user defined attribute exist in the final meta data part of assembly, is it possible to use reflector to see them? (I have tried but can not find.)
thanks in advance,
George
|
|
|
|
|
Yes, they can be reflected. Recently I'm working on a project implementing plug-in architecture and this is the way I identify plug-ins.
|
|
|
|
|
Thanks natsuyaki,
1.
Sorry my English is not good. You mean both .Net built-in and user defined attribute exist in the final meta data part of assembly, even for the method level attribute?
2.
How do you find the final values? Using reflector tool or?
Reflector tool I mean,
http://www.aisto.com/roeder/dotnet/[^]
regards,
George
|
|
|
|
|
My English is not so good too...
1. class level attributes exist in meta data, method level unkonown...
2. Using Type.GetCustomAttribute() to get custom attribute at runtime.
Or the tool ILDasm in .NET SDK or others.
|
|
|
|
|
Great natsuyaki!
How to use ILDasm to read meta data and attributes? I only find IL for each method/class from this tool.
regards,
George
|
|
|
|
|
If there is a custom attribute. It displays ".custom instance void[xxx]xxxxxx.xxxxAtribute::cctor()=........."
|
|
|
|
|
Great natsuyaki!
How to identify which parts of IL code are dealing with attribute definition? Any fields or keywords in IL identify?
regards,
George
|
|
|
|
|
You can write and compile an assembly with custom and built-in class/method level attributes. See if they exist in meta data using ILDasm.
|
|
|
|
|
Thanks natsuyaki!
I think you monitor the attribute in IL using ILDasm tool, not the below tool, right?
http://www.aisto.com/roeder/dotnet/
(the tool has a confusing name relfector, which makes me confused in the discussion context)
regards,
George
|
|
|
|
|
but it's really using reflection.~
|
|
|
|
|
|
The following IL code is retrieved by ILDasm:
class with SerializableAttribute:
<br />
.class public auto ansi serializable beforefieldinit ClassLibrary2.Class1<br />
extends [mscorlib]System.Object<br />
{<br />
}
method with ObsoleteAttribute:
<br />
.method public hidebysig instance void s() cil managed<br />
{<br />
.custom instance void [mscorlib]System.ObsoleteAttribute::.ctor() = ( 01 00 00 00 ) <br />
.maxstack 8<br />
IL_0000: nop<br />
IL_0001: ret<br />
}
|
|
|
|