Add method of list, etc.

Source: Internet
Author: User

1. In the past, the add method of list <t> was commonly used, so I didn't care much about it. It was often a problem.

 

Static list <Object> A = new list...

Addb void (){
Object B = new object;
A. Add (B );
}

 

B is a temporary variable. After the addb program is executed, object B is released. However, you can still access the value a [0.

I have read the msdn explanation of ADD.

"Before adding a new element, the capacity of list <(of <(T>)> is increased by automatically allocating an internal array and existing elements are copied to the new array. "

That is to say, when a executes add, it first applies for a piece of memory space and copies the content of B (memory copy ). Instead of storing the address of B in. List is not a linked list. Therefore, the elements in a are saved.

 

2. List <t> how to release it in time.

In wince programming, memory is limited, so we hope resources can be recycled by the garbage collector GC as soon as possible.

You can manually call

Staticclass. staticlist = NULL;
GC. Collect ();

Release resources in a timely manner.

 

3. dynamically add and use fonts in wince.

Wince API functions are required

Code

[Dllimport ("coredll", entrypoint = "addfontresource")]
Private Static extern int addfontresource ([IN, financialas (unmanagedtype. lpwstr)] string fontsource );

[Dllimport ("coredll", entrypoint = "sendmessage")]
Private Static extern int sendmessage (intptr hwnd, int MSG, intptr wparam, intptr lparam );

[Dllimport ("coredll", entrypoint = "removefontresource")]
Private Static extern int removefontresource ([IN, financialas (unmanagedtype. lpwstr)] string fontsource );

 

Run

Int installfont = addfontresource (@ "\ temp \ simsun. TTC ");
If (installfont! = 0)
{
Sendmessage (intptr) 0 xFFFF, 0x001d, intptr. Zero, intptr. Zero );
}

 

It must be released at the end; otherwise, memory leakage may occur.

Int removefont = removefontresource (@ "\ temp \ simsun. TTC ");
If (removefont! = 0 ){
Sendmessage (intptr) 0 xFFFF, 0x001d, intptr. Zero, intptr. Zero );
}

 

Sendmessage is used to notify all programs that the font has changed. VC # define wm_fontchange 0x001d;

Use the following program to view the fonts currently available

 

Installedfontcollection enumfonts = new installedfontcollection ();
Fontfamily [] fonts = enumfonts. Families;
Foreach (fontfamily font in fonts ){
MessageBox. Show (font. Name );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.