Click here to Skip to main content
15,905,508 members
Home / Discussions / C#
   

C#

 
GeneralRe: RegEx Question Pin
TheGreatAndPowerfulOz26-Jan-11 9:59
TheGreatAndPowerfulOz26-Jan-11 9:59 
GeneralRe: RegEx Question Pin
RobCroll26-Jan-11 12:55
RobCroll26-Jan-11 12:55 
QuestionReserve memory in Collection Pin
hairy_hats26-Jan-11 5:58
hairy_hats26-Jan-11 5:58 
AnswerRe: Reserve memory in Collection Pin
Yusuf26-Jan-11 6:43
Yusuf26-Jan-11 6:43 
AnswerRe: Reserve memory in Collection Pin
Luc Pattyn26-Jan-11 7:23
sitebuilderLuc Pattyn26-Jan-11 7:23 
GeneralRe: Reserve memory in Collection Pin
hairy_hats27-Jan-11 5:43
hairy_hats27-Jan-11 5:43 
GeneralRe: Reserve memory in Collection Pin
Luc Pattyn27-Jan-11 5:49
sitebuilderLuc Pattyn27-Jan-11 5:49 
AnswerRe: Reserve memory in Collection Pin
DaveyM6926-Jan-11 8:26
professionalDaveyM6926-Jan-11 8:26 
Collections such as List<T> (starting with a default capacity of 4) double their capacity once filled...
C#
List<int> list = new List<int>();
Console.WriteLine(list.Capacity); // 0

list.Add(0);
Console.WriteLine(list.Capacity); // 4

list.AddRange(new int[] { 1, 2, 3, 4 });
Console.WriteLine(list.Capacity); // 8

list.AddRange(new int[] { 5, 6, 7, 8 });
Console.WriteLine(list.Capacity); // 16

list.AddRange(new int[] { 9, 10, 11, 12, 13, 14, 15, 16 });
Console.WriteLine(list.Capacity); // 32

I believe they do this by allocating a new area in memory big enough to create the wrapped inner array with the new capacity then copying the existing elements to the new array. If these are large collections then that could be the source of the slowness, but unlikely unless the collection is having to resize many times.
You can avoid the new memory allocation and copying by specifying a suitable capacity for the collection in the constructor...
C#
List<int> list = new List<int>(DesiredCapacity);

Dave

Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.
Astonish us. Be exceptional. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)



AnswerRe: Reserve memory in Collection Pin
Luc Pattyn26-Jan-11 8:56
sitebuilderLuc Pattyn26-Jan-11 8:56 
GeneralRe: Reserve memory in Collection Pin
AspDotNetDev26-Jan-11 9:35
protectorAspDotNetDev26-Jan-11 9:35 
AnswerRe: Reserve memory in Collection Pin
AspDotNetDev26-Jan-11 9:41
protectorAspDotNetDev26-Jan-11 9:41 
QuestionGenerate from PDF images with iTextSharp? Pin
BoySetsFire26-Jan-11 5:56
BoySetsFire26-Jan-11 5:56 
AnswerRe: Generate from PDF images with iTextSharp? Pin
Yusuf26-Jan-11 6:47
Yusuf26-Jan-11 6:47 
GeneralRe: Generate from PDF images with iTextSharp? Pin
BoySetsFire26-Jan-11 8:29
BoySetsFire26-Jan-11 8:29 
GeneralRe: Generate from PDF images with iTextSharp? Pin
Yusuf26-Jan-11 8:50
Yusuf26-Jan-11 8:50 
QuestionHaving trouble with network account removal on local machine Pin
turbosupramk326-Jan-11 5:11
turbosupramk326-Jan-11 5:11 
QuestionReturn List<> frrom WebMethod Pin
huge_superman26-Jan-11 3:45
huge_superman26-Jan-11 3:45 
AnswerRe: Return List frrom WebMethod Pin
TheGreatAndPowerfulOz26-Jan-11 7:51
TheGreatAndPowerfulOz26-Jan-11 7:51 
GeneralRe: Return List frrom WebMethod Pin
huge_superman26-Jan-11 9:46
huge_superman26-Jan-11 9:46 
GeneralRe: Return List frrom WebMethod Pin
TheGreatAndPowerfulOz26-Jan-11 10:04
TheGreatAndPowerfulOz26-Jan-11 10:04 
GeneralRe: Return List frrom WebMethod Pin
Pete O'Hanlon26-Jan-11 10:04
mvePete O'Hanlon26-Jan-11 10:04 
QuestionGet assembly name that called class library Pin
Chesnokov Yuriy26-Jan-11 1:23
professionalChesnokov Yuriy26-Jan-11 1:23 
AnswerRe: Get assembly name that called class library Pin
Pete O'Hanlon26-Jan-11 1:31
mvePete O'Hanlon26-Jan-11 1:31 
GeneralRe: Get assembly name that called class library Pin
Chesnokov Yuriy26-Jan-11 1:36
professionalChesnokov Yuriy26-Jan-11 1:36 
GeneralRe: Get assembly name that called class library Pin
Henry Minute26-Jan-11 2:07
Henry Minute26-Jan-11 2:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.