|
lol,
i looked in the regex forum for his post, but he didn't post there so i answered here.
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
Thats right, you start off with one problem and introduce a Regex expression and now you have two problems.
Architecture is extensible, code is minimal.
|
|
|
|
|
Hi all,
Is there an equivalent of the stl::vector<>.reserve() function for .NET Collections?
I'm building a large menu dynamically and it's a slow process and I either need to speed it up (hence my question) or do it all a different way.
|
|
|
|
|
Remember C# is managed code, the whole notion is to free you up from allocation/deallocating.
Which .NET collection class are you using? May be if you post your code snippets it may be helpful understanding as to what is going on on your code.
|
|
|
|
|
Generic collections offer at least one constructor that takes an initial capacity; having said that, I don't believe it is the growth of the collection itself that causes a noticeable slowdown. Telling more about your app, maybe showing some relevant code, would enable people to give some specific advice.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Luc Pattyn wrote: Generic collections offer at least one constructor that takes an initial capacity
Thanks Luc, I'd missed that one. I was dynamically filling a ContextMenuStrip from an XML file that had over 400 entries each in two submenus, but I've changed it to use statically filled ToolStripComboBox es instead and it starts immediately.
|
|
|
|
|
You're welcome.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Collections such as List<T> (starting with a default capacity of 4) double their capacity once filled...
List<int> list = new List<int>();
Console.WriteLine(list.Capacity);
list.Add(0);
Console.WriteLine(list.Capacity);
list.AddRange(new int[] { 1, 2, 3, 4 });
Console.WriteLine(list.Capacity);
list.AddRange(new int[] { 5, 6, 7, 8 });
Console.WriteLine(list.Capacity);
list.AddRange(new int[] { 9, 10, 11, 12, 13, 14, 15, 16 });
Console.WriteLine(list.Capacity);
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...
List<int> list = new List<int>(DesiredCapacity);
|
|
|
|
|
I stumbled upon a little article here[^] that seems to confirm what you said.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Wow, that author is brilliant! So is this one!
|
|
|
|
|
Some things you can try:
- Set the intial capacity of the list as large or larger than you think you'll need it (as others have mentioned, the List class has a constructor for this purpose). This could potentially cut the time in about half.
- Use structs rather than classes so the memory will be allocated immediately rather than in small chunks over time.
- Recycle your objects (that is, don't make new objects... save them for use later).
|
|
|
|
|
Hi,
I want to generate from an PDF Images.
But how??
My favorite iTextSharp.
thx
|
|
|
|
|
|
Thanks Yusuf!
I now... but i can´t find a exampel (iTextSharp) to gernerate thumbnails
In IText NOT in ITextSharp can i use this function: decoder.getPageAsImage(PageNumber)
But how can i create thumbnails with iTextSharp???
thx!!!
|
|
|
|
|
I don't know as I never worked with iTextSharp.
We use imagemagick[^] and GhostScript[^] to generate thumbnails of PDF files. But that is completely different way of doing it.
Is there something you can make use in here[^]?
|
|
|
|
|
I am trying to write code so that if the local admins are not certain predefined accounts or groups, then they are removed.
The closest I have gotten is the code below, but it stops at the children.Remove(badObject) line and fails saying it isn't the correct format. Can anyone help please?
string userName = "WinNT://computername/test12";
userName = userName.Substring(userName.Length - 6);
DirectoryEntry de = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
DirectoryEntries children = de.Children;
DirectoryEntry badObject = children.Find("userName");
children.Remove(badObject);
de.CommitChanges();
|
|
|
|
|
Hi Guys,
Wondering if you can help me figure this out.
Here is an Example:
I have a class:
---------------
This class exist in my web service as well as my test windows appication.
public class ADUser
{
private string _name;
private string _surname;
public string Name{get {return _name;}set {_name = value;}}
public string Surname{get {return _surname;}set {_surname = value;}}
}
Here is an example of my Web Service and WebMethod:
---------------------------------------------------
List<ADUser> mylist = new List<AdUser>();
AdUser user = null;
//The method populates users from active directory into a list
private void PopulateList()
{
foreach (User in active directory)
{
user = new AdUser();
user.Name = "displayName";
user.Surname = "lastname";
mylist.Add(user);
}
}
[WebMethod]
public List<ADUser> GetUserList()
{
PopulateList();
return mylist;
}
This is my Desktop Application
------------------------------
WebService1 ws = new WebService();
List<ADUser> list = new List<ADUser>();
list = new List<ADUser>(ws.GetUserList());
This is the error I get:
The best overloaded method match for 'System.Collections.Generic.List<WindowsFormsApplication1.ADUsers>.List(System.Collections.Generic.IEnumerable<WindowsFormsApplication1.ADUsers>' has some invalid arguments
and if I user list = ws.GetUserList(); I get the error:
Cannot implicitly convert type 'WindowsFormsApplication1.myService.ADUsers[]' to 'System.Collections.Generic.List<WindowsFormsApplication1.ADUsers>
I have tried list.AddRange I have tried Arrays. All I want is the list that gets populated in my web service to be returned to my application.
Could you please help..
Thanks
|
|
|
|
|
even though you've declared that the WebMethod returns a List<aduser>, the interface is simplified to ADUser[] (array of ADUser).
So, you need to use the ToList() extension method
using System.Linq;
...
List<ADUser> list = ws.GetUserList().ToList();
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
Hi ahmed,
I tried using List<ADUsers> list = ws.GetUserList().ToList();
This is the error I get now:
Cannot Implicitly convert type System.Collections.Generic.List < WindowsFormsApplication1.myService.ADUsers > to
System.Collections.Generic.List < WindowsFormsApplication.ADUsers >
|
|
|
|
|
somehow you're using an ADUsers class from two different namespaces. C# will see these as two different types (as indeed they are) even if they are identical in definition.
Make sure the declaration of
List<ADUsers> list
is using the same namespace as the one from
ws.GetUserList()
see your using statements for a clue.
Or try
List<WindowsFormApplication1.myService.ADUsers> list = ws.GetUserList().ToList();
do you understand?
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
The clue to the problem is in the error, and it's hard to spot at a glance. Basically though, you are trying to cast WindowsFormApplication.ADUsers to WindowsFormApplication1.ADUsers (I've highlighted the difference). In other words, you have 2 versions of ADUsers; one in WindowsFormApplication and one in WindowsFormApplication1, and they aren't the same class.
|
|
|
|
|
There is some application .exe and class library .dll.
Exe uses dll functions.
Is it possible inside dll code get exe assembly that calls its functions?
Чесноков
|
|
|
|
|
|
I need exe name, full path, version, architecture.
GetCallingAssembly and GetExecutingAssembly returns .dll one, not .exe
Чесноков
|
|
|
|
|
GetEntryAssembly?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
|
|
|
|