Monday, January 18, 2016

single-threaded apartment

/*Rules for single-threaded apartments are simple, but it is important to follow them carefully: Every object should live on only one thread (within a single-threaded apartment). Marshal all pointers to objects when passing them between apartments./*传统线程可以访问同进程内的资源*/ Each single-threaded apartment must have a message loop to handle calls from other processes and apartments within the same process. Single-threaded apartments without objects (client only) also need a message loop to dispatch broadcast sendmessages that some applications use. DLL-based or in-process objects do not call the COM initialization ;Each thread of a client process or out-of-process server must call CoInitialize, or call CoInitializeEx and specify COINIT_APARTMENTTHREADED for the dwCoInit parameter。The main apartment is the thread that calls CoInitializeEx first. DLL-based or in-process objects register their threading model with the ThreadingModel named-value under the InprocServer32 key in the registry. Apartment-aware objects must also write DLL entry points carefully. */ COM creates a hidden window using the Windows class "OleMainThreadWndClass" in each single-threaded apartment. A call to an object is received as a window message to this hidden window. When the object's apartment retrieves and dispatches the message, the hidden window will receive it. The window procedure will then call the corresponding interface method of the object. Single-threaded apartments can implement IMessageFilter 。 综上,单线程套间本质上是一个类(接口),保存着一个窗口句柄、一个线程(线程先初始化com库[就是注册],然后有消息loop)、0或多个组件对象、客户线程(也需要在com注册),该类(接口)可以进一步实施IMessageFilter接口。

In-Process Server Threading Issues

Like other servers, in-process servers can be single-threaded, apartment-threaded, or free-threaded. These servers can be used by any OLE client, regardless of the threading model used by that client. For an in-process server, when the threading model of the client and in-process server differ, COM must interpose itself between the client and the object. When an in-process object that supports the single-threaded model is called simultaneously by multiple threads of a client, COM cannot allow the client threads to directly access the object's interface—the object was not designed for such access.Instead, COM must ensure that calls are synchronized and are made only by the client thread that created the object. Therefore, COM creates the object in the client's main apartment and requires all the other client apartments to access the object by using proxies. When a free-threaded apartment (multithreaded apartment model) in a client creates an apartment-threaded in-process server, COM spins up a single-threaded apartment model "host" thread in the client. This host thread will create the object, and the interface pointer will be marshaled back to the client's free-threaded apartment. Similarly, when a single-threaded apartment in an apartment-model client creates a free-threaded in-process server, COM spins up a free-threaded host thread (multithreaded apartment on which the object will be created and then marshaled back to the client single-threaded apartment). COM helps protect access to objects provided by a single-threaded DLL by requiring access from the same client apartment in which they were created. In addition, all of the DLL entry points (like DllGetClassObject and DllCanUnloadNow) and global data should always be accessed by the same apartment. COM creates such objects in the main apartment of the client, giving the main apartment direct access to the object's pointers. Calls from the other apartments use interthread marshaling to go from the proxy to the stub in the main apartment and then to the object. This allows COM to synchronize calls to the object. Interthread calls are slow, so it is recommended that these servers be rewritten to support multiple apartments. single-threaded的全称应该是single-thread-per-process。

COM Fundamentals

COM requires that the only way to gain access to the methods of an interface is through a pointer to the interface. An interface definition specifies the interface's member functions, called methods, their return types, the number and types of their parameters, and what they must do. There is no implementation associated with an interface. COM interfaces are immutable—You cannot define a new version of an old interface and give it the same identifier. Adding or removing methods of an interface or changing semantics creates a new interface, not a new version of an old interface. Therefore, a new interface cannot conflict with an old interface. However, objects can support multiple interfaces simultaneously and can expose interfaces that are successive revisions of an interface, with different identifiers. Thus, each interface is a separate contract, and systemwide objects need not be concerned about whether the version of the interface they are calling is the one they expect. The interface ID (IID) defines the interface contract explicitly and uniquely. All COM objects must implement the IUnknown interface。 For any given object instance, a call to QueryInterface(IID_IUnknown, ...) must always return the same physical pointer value(((IUnknown*)*ppv)->AddRef(); ). This allows you to call QueryInterface(IID_IUnknown, ...) on any two interfaces and compare the results to determine whether they point to the same instance of an object. Containment/Delegation(包容/托管) the outer object explicitly delegates implementation to the inner object's methods,That is, the outer object uses the inner object's services to implement itself.显然所有com对象都支持包容。 Aggregation is actually a specialized case of containment/delegation.the outer object exposes interfaces from the inner object as if they were implemented on the outer object itself. The following rules apply to creating an aggregable object: The aggregable (or inner) object's implementation of QueryInterface, AddRef, and Release for its IUnknown interface controls the inner object's reference count, and this implementation must not delegate to the outer object's unknown (the controlling IUnknown). The aggregable (or inner) object's implementation of QueryInterface, AddRef, and Release for its other interfaces must delegate to the controlling IUnknown and must not directly affect the inner object's reference count. The inner IUnknown must implement QueryInterface only for the inner object. The aggregable object must not call AddRef when holding a reference to the controlling IUnknown pointer. When the object is created, if any interface other than IUnknown is requested, the creation must fail with E_NOINTERFACE.

Sunday, November 29, 2015

在温哥华办理美国签证攻略

在温哥华办理美国签证攻略

非移民签证常见类型

  • CNMI-only(仅限于美国北玛利安纳群岛) transitional worker(CW-1).
  • business visitor商务访问(B-1)
  • Exchange visitor交换访问(J)
  • Intra-company transferee公司内部穿梭(L)
  • Tourism, vacation, pleasure visitor旅游(B-2)

照片场景要求

  • Sized such that the head is between 1 inch and 1 3/8 inches (22 mm and 35 mm) or 50% and 69% of the image's total height from the bottom of the chin to the top of the head.
  • Taken in front of a plain white or off-white background

照片拍摄和处理要求


Dimensions The image dimensions must be in a square aspect ratio (the height must be equal to the width). Minimum acceptable dimensions are 600 x 600 pixels. Maximum acceptable dimensions are 1200 x 1200 pixels.
Color The image must be in color (24 bits per pixel) in sRGB color space which is the common output for most digital cameras.
File Format The image must be in JPEG file format
File Size The image must be less than or equal to 240 kB (kilobytes).
Compression The image may need to be compressed in order for it to be under the maximum file size. The compression ratio should be less than or equal to 20:1.

详细流程

  1. 浏览 领事电子申请中心 以申请非移民签证。
  2. ...

Saturday, November 21, 2015

FOREX Trader(FOREXTrader) insturctions

FOREX Trader(FOREXTrader) insturctions

list of vocabularies

Trading Handbook

bollinger_bands

Fees

FOREX.com charges no trading commissions or transaction fees. FOREX.com charges a data fee of $15 per month if there is no trading activity or no open positions for a period of 90 days or more. Contact us if you wish to disable your account temporarily and avoid this fee.

Order Basis/Mode

Market orders:Market orders are executed at the best available price at the time the order is received. always check the market price before you make orders.

Limit Orders: Limit orders are executed at the order rate or better. Sell limit orders are filled when the bid(买家出价) reaches the requested rate; buy limit orders are filled on the offer(zxxu:to say, immidiately making the order).

Stop Orders: Stop orders become market orders when a predefined order rate is reached. Stop orders are executed at the best available price, depending on available liquidity. Buy Stop orders are filled on the offer price and Sell Stop orders are filled at the bid price.

Orders can be set to open a new position or close an existing position. To set a limit order to open a new position, you are trying to get a “better” price to buy or sell. Let’s say USDCAD is currently at 1.3000, a “better” price to buy is a price lower than 1.3000 or a “better” price to sell is a price higher than 1.3000. Stop is basically the opposite of limit, so you would set a buy order higher than the current price or a sell order lower than the current price.If you set an order to close a position, then limit means take profit and stop means stop loss.

Order Expiry

End of Day (EOD) orders automatically expire at 5pm ET on the same day the order was entered(Note:opening prices may differ significantly from the previous day's close.). Good till Cancelled (GTC) orders automatically expire on the Saturday following the 90th calendar day from the date the order was entered.

Orders Left Over the Weekend or Holidays

FOREX.com's trading hours are from Sunday at 5pm ET through Friday at 5pm ET. Orders left pending over a weekend or holiday period will not be executed until FOREX.com resumes regular trading hours.

Order Types

One Cancels Other (OCO's):A contingent(有条件的) order providing that one part of the order is cancelled if the other part is executed. If one part of the order is filled, the other is automatically cancelled.

An If/Then order provides that if the first order ("If" order) is executed, the second order ("Then" order) becomes an active unassociated single order. Unassociated orders are not attached to a trade and act independently of any position updates. In cases where the “If” order does not execute, the “Then” single order will remain dormant and will not be executed when the market reaches the specified rate. When either part of an If / Then order is cancelled, all parts of the order are cancelled as well.

An If/Then OCO provides that if the first order ("If" order) is executed, the second order ("Then" order) becomes an active unassociated OCO order. The execution of either one of the two "Then" orders automatically cancels the other. When any part of an If / Then OCO order is cancelled, including either leg of the OCO order, all parts of the order are cancelled as well.

A trailing stop allows a trade to continue to gain in value when the market price moves in a favorable direction, but automatically closes the trade if the market price suddenly moves in an unfavorable direction by a specified distance.

When the market price moves in a favorable direction, the trigger price follows the market price by the specified stop distance. If the market price moves in an unfavorable direction, the trigger price stays stationary and the distance between this price and the market price becomes smaller. If the market price continues to move in an unfavorable direction until it reaches the trigger price, an order is triggered to close the trade.

Rollovers

rollovers

什么是rollovers

当你买入一种货币对的时候,你要么支付利息,要么获得利息(charges or credits)。以下是专家的解释:" You can think of rollovers as putting money into one bank and borrowing money from another bank. For example: Let's say you want to earn on the rollover (interest differential between two countries/banks). The Bank of England (GBP)'s interest rate is 5.5%. The Bank of Japan (JPY)'s interest rate is 0.5%. If you wanted to in this circumstance you would borrow money from the Bank of Japan (0.5%) and deposit it into the Bank of England (+5.5%), thus earning 5.0% on the money you borrowed. However, the rates are compounded daily, thus causing a much smaller interest rate differential. The same principles apply when you buy (go long), on the currency pair GBP/JPY. Essentially you are buying the GBP (the base currency) and selling JPY (the counter currency) at the same time. Because the interest rate is currently higher on the GBP (Bank of England) than the JPY (Bank of Japan), you will earn interest on the position when rolled over.... The exception is a position opened and held overnight on Wednesday. The normal value date would be Saturday(not next day); because banks are closed on Saturday the value date is actually the following Monday. Due to the weekend, positions held overnight on Wednesday incur or earn an extra two days of interest. Trades with a value date that falls on a holiday will also incur or earn additional interest.... "

rollover总是在16:59进行,也就是加拿大14:59(冬令时), 所以在这个时间点之前平仓就可以避免rollovers问题。

如何确定rollovers

加拿大人最好在http://www.forex.com/ca/trading-platforms/forextrader/pricing/rollovers.html查看每天的rollovers(Rollovers are calculated based on 10,000 position, and amounts are in USD), 或者在forex客户端查看。

影响rollovers的条件

  • The interest rate differentials between the country's associated with the pair you're trading. Have a glance to http://www.global-rates.com/interest-rates/central-banks/central-banks.aspx as a quick reference.
  • the day of the week(一般来说在周三最有利)

以下几点要注意:

  • FOREX.com 会对各国银行interest rate进行修正,这也是他们的赚点之一。
  • 对于当前利息差别很大的两个国家,每天的rollover值变化不大。
  • 即使是高级客户也不享受rollovers的优惠。