开发者

Predefined capacity when marshalling a List<> in WCF

开发者 https://www.devze.com 2023-02-26 07:03 出处:网络
I am marshalling a List using WCF and an 开发者_运维技巧\'ref\' parameter and I want to be able to set the capacity.

I am marshalling a List using WCF and an 开发者_运维技巧'ref' parameter and I want to be able to set the capacity.

Some background. I am marshalling 2 List's using ref so that the calling function can determine which List it is interested in by initialising prior to the call.

Thus a quick test for null enables the service to do something with the list. This all works fine.

But I thought; I know there is going to be 100~ items in the list so setting an initial capacity is a good idea but when I do so in the calling function it is set back to 0 in the WCF service.

Any clues?

Thanks muchly.

EDIT: Thinking about it - this does make an enormous amount of sense does it. Any allocated resources from setting an initial capacity would have to be (wastefully) marshalled and then rehydrated/allocated.

I think a second parameter with a size or just hard coding it is in order.


WCF passes all data by value. It never passes values by reference. Collections are transfefred as arrays so no additional information except contained data are transferred. Parameters marked as ref and out only defines which direction is the parameter transfered and also instruct proxy to fill existing instance with deserialized data (in case of ref).

If you want to transfer some information like capacity you must transfer it in separate parameter and use it in service to limit number of returned data.

0

精彩评论

暂无评论...
验证码 换一张
取 消