For Each Loop Enumerator Expression And Memory Consumption

Aug 15, 2011

According to the language specification guide for VB.NET Section 10.9.3. The enumerator expression in a for each loop is copied over into memory. If I have a list of 10000 objects that list will be in memory twice for the code below?
dim myList as new list(of bobs)
'put 10000 bobs in my list
for each x In myList
'do something
next

If I were generating the list from a linqQuery or some other such query it would make sense to generate that list at the for each loop statement thus not having the list in memory twice for example.
for each x in myList.where(function(x) x.name = Y)
'do something
next

If the LINQ query is unreadable on the for each loop, do I forgo readability and just put it on the for each loop declaration line? Should I declare the list in its own variable and just bite the bullet and have the list exist twice in memory?

View 1 Replies


ADVERTISEMENT

.NET WinForm Memory Consumption?

Apr 19, 2011

I've been profiling a WinForm's application using ".NET Memory Profiler".I can't quite seem to understand how my application is growing to 1GB, then 2GB, then 3GB of usage - according to windows task manager.

The private bytes using that tool, and "Total Bytes in All Heaps" shows only as 70MB or so. At the top of my list of instances hanging around, they are mostly String, or WeakReferences to lots of little objects.

All the application is doing is showing a form that loads data from a database. I repeat the show/dispose cycle of the form about 100 times and the growth is continuous.I've tried about 3 memory profiling tools now and none of them are showing me where this enormous amount of memory consumption is coming from.

View 3 Replies

What Is The Effective Way To Reduce The Memory Consumption

Apr 5, 2011

I found what seems to be an easy and effective way to reduce the memory consumption of my vb.net app. What I need to know is how "correct" or "proper" is the method I'm using for my application and what exactly is going on behind the scenes that I should worry about? I want to release memory every time a form closes. Here is how I reduce the required memory of my program:[code...]

View 7 Replies

Measuring Memory Consumption Of A Function That Accesses A Database?

Sep 16, 2011

I have a VB Function (in Visual Studio 2008 with .NET 3.5) that opens up a connection to an Oracle database and queries the database for information. Apparently after some trial and error, I discovered when the SQL statement is being processed and filling the dataset, it apparently is taking up too much memory trying to complete the task. I'm running into System.OutofMemory exceptions and other unpleasantness.I'm wondering, is there some sort of program out there to measure memory consumption of your SQL code that is being processed in a Visual Studio application?

View 1 Replies

Measuring Memory Consumption Of Function That Accesses Database

Aug 25, 2009

I have a VB Function (in Visual Studio 2008 with .NET 3.5) that opens up a connection to an Oracle database and queries the database for information. Apparently after some trial and error, I discovered when the SQL statement is being processed and filling the dataset, it apparently is taking up too much memory trying to complete the task.I'm running into System.OutofMemory exceptions and other unpleasantness.I'm wondering, is there some sort of program out there to measure memory consumption of your SQL code that is being processed in a Visual Studio application?

View 2 Replies

VS 2008 - Normal Versus MDI Form (Memory Consumption)

Mar 11, 2010

I did a project (College Management) in vb.net 2008 which contains 13 forms in it. I designed the different functions in a different normal form, i.e. frmAdmission, frmSearch etc. When the project run's the main form is loaded. When user chooses a particular function say 'frmSearch' then the main form is unloaded and the form frmSearch is loaded. Now my lecturer told me to use MDI forms instead of normal forms because, normal forms takes larger memory than the MDI forms.

View 5 Replies

List That This Enumerator Is Bound To Has Been Modified - An Enumerator Can Only Be Used If The List Does Not Change?

Apr 25, 2009

For
Each
Item As
DataRowView In
lbOrdersNeedToBeVoided.Items

[code]....

View 6 Replies

C# - Xpath Expression To Loop Through Xmldocument?

Feb 19, 2012

trying to parse this:

<?xml version="1.0" encoding="UTF-8"?>
<directoryresponse xmlns="https://www.sisow.nl/Sisow/REST" version="1.0.0">
<directory>[code]......

Here's my code:

XPath = "//directoryresponse/directory/issuer/issuerid"
Dim nodeList As XmlNodeList = XML.SelectNodes(XPath)

but nodelist.count=0...why?

View 3 Replies

For Loop - PictureBox Is Type And Cannot Be Used As Expression

Mar 7, 2012

I have some problems with a for loop in visual basic.
Public Const numofblocks As Short = 88
Public Shared blocks(numofblocks) As PictureBox
For x = 1 To numofblocks
blocks((x)) = PictureBox(x)
Next
The error raised at the picturebox statement: PictureBox' is a type and cannot be used as an expression. The result of this for loop is that every picturebox in the designer form is named: blocks([number of picturebox]). I need this for some other for loops.

View 6 Replies

Out Of Memory Exception / Parallel.For Loop / Large Numbers?

Nov 27, 2011

I need some guidance on a little program I'm making (one that I thought would take a couple of hours from start to finish, it's been days now ...) that determines all of the proper divisors of any given number up to the maximum value of a UInt32.

View 8 Replies

Enumerator Within A USING Block?

Jul 20, 2010

I tried utilizing a collections Enumerator inside of a USING block to take care of the Enumerator.dispose call for me, however, I'm getting NullReferenceExceptions when trying to access the Enumerator.Current property after doing a MoveNext.

[Code]...

View 2 Replies

FadeMode - How To Declare Enumerator

May 21, 2009

I have these variables as shown below. The FadeMode is assigned on of the 3 integer values. I would like it to work like an enumerator, so that when I working with the code editor, IntelliSense offers a choice of the 3 possible values. Like x = Fademode.FadeOut

Const FadeIn As Integer = 0
Const FadeOut As Integer = 1
Const FadePause As Integer = 2
Friend FadeMode As Integer = FadeIn

View 2 Replies

Monitor The Power Consumption?

Sep 18, 2009

I am looking to record information about the computers power consumption over time, is there any way I could do this using vb, I can get the current voltage from the processor but do not know the current therefore can not work out the wattage. I know of application which do have power consumption recorders but I would like to create my own.

View 1 Replies

Using An Enumerator To Parse A Collection?

Feb 13, 2009

If I am using an enumerator to parse a collection such as

Code:
''' <summary>
''' Checks to see if Node1 is a direct child of Node2
''' </summary>

[Code].....

The object comparison of Enumerator.Current and Node1 passes an option strict check, but should I for readability and or for any other reason cast it to the correct type? I know their object references will ultimately be checked the same way, but is it generaly bad form to assume this?

Second question. I recently came across the use of the Enumerator v/s a For/Each loop through the collection, does anyone know the pros/cons of the use of either in specifi situations. Where one is favorible to the other or where they should or should not be used?

View 2 Replies

Construct Enumerator At Runtime From XML File

Jul 17, 2010

I am looking for a way to read an XML file at run time and construct an Enumerator from it. I got the reading and writing all working, it's just getting all the strings to create an enumerator that's the tricky part. I could get them into a collection of strings or maybe a dictionary, but not sure how to go about converting from these into an enumerator. The goal of this is to allow users to add and delete items from the underlying enumerators and eliminate writing hard coded enumerators. My idea is to allow users to extend the program without coding. This is a Winform vb app thats not using any database but just XML files to store and retrieve things.

View 7 Replies

Passing A List's Enumerator To A Function

Dec 2, 2011

It looks like passing a list's enumerator to a function "byval" is quite different than passing it "byref". Essentially, regular "byval" passing will NOT change the caller's "enumerator.Current value", even if the function advances the enumerator. I was wondering if anyone knows why this is the case? Is an enumerator a primitive like an integer, without an object reference, and hence changes to it don't get reflected in the caller?This function is byval, and gets stuck in an infinite loop, spitting out "1" message boxes, because the enumerator's "current" never advances past 5.[code]The difference between the two functions is only whether the listFirstItem__ function accepts a byval or a byref enumerator.

View 2 Replies

Event Consumption For Concurrency In A Multicore Application?

Jan 18, 2010

Target machine 4 core AMD I have an event that is raised my the main thread of the application. The event is consumed by several different classes in the application. I want them all to run concurrently up to the max cores available and then que the rest in order.The work routine in each class is relatively small but concurrency is the goal.Considering this.

A. Create a background worker on each classes initialization and have the event handler start the worker.

B. Create a delegate to the do-work sub that is called by the event handler

A- Pros - worker is only created once and reusable so only pay creation cost once.

A-Cons could create a ton of workers that consume resources eventually.

B- Pros Smaller thread pool

B- Cons Lot of overhead

View 2 Replies

Unable To Understand Enumerator's Reset's Purpose?

Dec 30, 2009

if a call to For Each starts by calling the Enumerator's MoveNext, then Current, then MoveNext, then Current, and so on until MoveNext returns a False then it exits, am i right to say that the Reset is never called?initially i thought that Reset would be called when MoveNext returns False, i tried this (a msgbox would come if it was ever called but i got no msgbox at all)

[code]...

if that's the case, what exactly is the use of the reset in an ienumerator, and is it ok to leave it empty, as such

View 4 Replies

Make Loop To Make Certain Thing Happen About 10-30 Times Without Taking In Too Much Memory / CPU?

Oct 16, 2011

A few years ago I have been busy creating this application but it didn't succeed, now Im coming back to it and similar problems occur. Basically I use SetPixel on a given window to draw a line, work fine, but the line goes away as the window redraws itself.The problem: I have been putting timers and threads on it to make sure the line is being drawn. Is there any way to make a loop to make a certain thing happen about 10-30 times without taking in too much memory/CPU?

View 7 Replies

GC Free The Memory Associated To The Arrays "in Time" For The Next Loop ?

Jul 19, 2011

I have a system that must do massive array operations. Often I have many arrays with 1 to 2 million elements at same time.

Usually I create the arrays inside a procedure, so, I expect when the array variable goes out of scope, the array becomes available to the GC. But in the near future, I'll need to do these operations in a "looping" way, so I'll create and delete the arrays many times...

Will GC free the memory associated to the arrays "in time" for the next loop or it is best to "force" it in someway, like using the erase statement? Or maybe I'm completely wrong?

View 1 Replies

VS 2005 Display In A Datagrid Total Consumption Of Gas (litres) With Kilometers Driven (mileage) Between 2 Dates

Aug 29, 2011

i am doing a small project for my business and i got stuck with this 2 weeks ago and still no progress.I have an access db table "store" that has columns: (filldate,brand,model,plateno,mileage,litres) where i am storing these info each time a car in my company fills gas. For example8/25/2011,Renault,Megane,5487844,3943,20).What i want to do now is to display in a datagrid the total consumption of gas (litres) with the kilometers driven (mileage) between 2 dates.

View 2 Replies

Delegate 'System.Threading.ThreadStart' Requires An 'AddressOf' Expression Or Lambda Expression As The Only Argument To Its Constructor?

Jan 23, 2010

I got this Error. below is my code.

GenerateTheList is function.Need help
Private Sub buttGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttGenerate.Click
Dim thread1 As New Thread(New ThreadStart(GenerateTheList))
thread1.Start()
End Sub

View 1 Replies

Get Current Enumerator (iterator) In LINQ Query / Like A Current Index In For Loops

Sep 20, 2011

Is that possible to get current Enumerator (...or iterator? Don't know which tern is the correct one) in a LINQ query ? For example, I try to create a XML output (via LINQ to XML) of all currently loaded assemblies. [code] is it possible to somehow get current "index" (counter?) from LINQ's Selects? I would like to use it in XML. [code]

View 1 Replies

Code To Put In An Expression To Add Database Columns In A Row And Display It In The Expression Column

Mar 21, 2010

While looking in the dataset designer for a database table I am doing in visual basic 2008 I found a line for expressions under the property menu for a specific column. I need to know the code that I would put in this expression line so that this column adds up the numbers I input into three other columns and displays that number in the column. I need it to automatically calculate this for each row in the database table.

View 13 Replies

Loading An Image From A Jpeg That Exists In Memory (but Not On Disk) Using Direct Memory Access

Nov 5, 2009

In VB 2005, I am calling a C++ DLL function that returns the address in memory and size in bytes of a jpeg image. How can I load that jpeg image directly from memory into a picture box in my VB form? I cannot afford to save it to disk first.

View 10 Replies

DataColumn.Expression: How To Use A User Defined Function In Expression

Oct 12, 2010

I am trying to write following expression on a datacolumn. But it results in error:Replicate('*', nLevel) + NameWhere: Replicate() is a user defined function (in a module). nLevel and Name are two other columns in same data table.

View 3 Replies

Expression Parsing Using FLEE And Custom Expression Context

Jun 12, 2012

I am using Flee to build a formula builder. It works great but the only problem I'm facing is that Flee doesn't understand Generic Methods I guess. I have a function called IIf declared in the expression context I'm using. [code]How can I work around this. I mean cannot , in sense, write all possible overloads of the function of all .net primitive types. What approach should I take.

View 1 Replies

Attempted To Read Or Write Protected Memory / Often An Indication That Other Memory Is Corrupt

May 22, 2007

Im getting a problem with one of my programs I have made in visual basic.NET where it gives me a memory error when i debug the program in the IDE. the exact error is this: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt". My program basically has a few forms with text fields on that get their text values from an access database on the same hard drive. Im wondering if im doing something wrong because my program just seems to eat up memory whenever it does anything. For example I have one form that has a combobox on it and when you change the drop down list selection it retreives a few strings from the database and puts them into the relevant text boxes, if you keep changing the selection then the memory usage (in task manager) just keeps going up and up. occasionally I get the error mentioned above when debugging but in my built version of the program it throws an exception everytime the memory usage gets past 49K.

Also I noticed when debugging in the "immediate window" frame I get the following message often:A first chance exception of type 'System. Invalid OperationException' occurred in System.Data.dll...Do I need to somehow be "releasing" the memory that is used to gather data once it becomes redundant?

View 12 Replies

Attempted To Read Or Write Protected Memory. This Is Often An Indication That Other Memory Is Corrupt

Nov 24, 2011

I am using the following code

This error occurs :

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Public Class FormRegEnumValue

[CODE]......................

View 2 Replies

Attempted To Read Or Write Protected Memory. This Is Often An Indication That Other Memory Is Corrupt?

Feb 1, 2009

QuoteSystem.AccessViolationException was unhandled Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Source="System.Windows.Forms"

Im designing a web browser and i continue to receive this error after going to about 3 websites it crashes with that error.

View 6 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved