How to dynamically resize an array?

  • Thread starter Thread starter roidy
  • Start date Start date
In the previous version of the program I just gave
the array a large value eg. 40 as it is unlikely any
season of a TV series will have that many episodes.
I`m just tidying the program up and it seemed wasteful to declare an array
that large . . .

That's a piffling amount of memory, almost nothing at all these days. If
you're worried about a few hundred bytes then you'd better get rid of all
that dotnet framework immediately because it is gobbling up huge amounts of
memory!

Mike
 
[Addressed to Roidy] You know, if you are going to take
the stupendously stupid way of reading the file in to memory
all at once . . .

The OP knows in advance roughly how much data he is dealing with and there
is nothing wrong with loading fairly large chunks of data into memory all at
once as long as it is known in advance that they are going to be a
reasonable size. Even quite very large chunks are perfectly acceptable these
days. The dotnet framework does it all the time!

Mike
 
[Addressed to Roidy] You know, if you are going to take
the stupendously stupid way of reading the file in to memory
all at once . . .

The OP knows in advance roughly how much data he is dealing with and there
is nothing wrong with loading fairly large chunks of data into memory all at
once as long as it is known in advance that they are going to be a
reasonable size. Even quite very large chunks are perfectly acceptable these
days. The dotnet framework does it all the time!

Mike
 
Tom said:
I've not looked at the implementation of the .NET XPath classes - so, I can't
be sure how they are implemented. Though, there are basically two ways to
work with XML data, and that is DOM which loads the entire XML document model
into memory or using an XmlReader to stream the data. But, my comment had not
to do with that anyway. It was derived from comments made further up the
thread, where things like split and File.ReadAllLines were being discussed.

Right, thats was before the OP stated the XML details of what he was
doing. :)
As for the size of files being less of a concern... That must be very domain
specific, because it's something I have to worry about quite often - so I take
it seriously when I see entire files slurped up in one fell swoop in
production code :) I've seen servers brought to their knees from this
seemingly simple method of reading data.

I was speaking in general, dealing with larger files today is
generally not given a 2nd thought until one has system performance issues.
I'm not saying I never use stuff like File.ReadAllLines - but, I try to
carefully weigh the alternatives before I make this sort of decision.
right.
You think that XPath syntax is more straight forward then the simple statement
above? I'm not saying don't learn XPath, because there are times you need it
even with LINQ - but, LINQ is definately easier and more straight forward.

The above does look easy. I don't know LINQ, but in general, I am use
to the slash "/" path method, its more standardize method and it
directly applies to tag based data representations. Its used in other
technologies too, like CSS, DOM and now that Microsoft officially
supports jQuery in ASP.NET, XPATH DOM element look ups is supported. I
don't you will be able to use LINQ on the client side.
Anything is doable. But why reinvent the wheel? Use the tools that
LINQ is in .NET.

Thanks for highlighting LINQ as an alternative method.

I just looked up LINQ. For the general public, here is a good link:

http://msdn.microsoft.com/en-us/library/bb397897.aspx
Introduction to LINQ

Comparison of XPath and LINQ to XML
http://msdn.microsoft.com/en-us/library/bb675156.aspx

Is it for VS2008 and .NET 3.5 only?

Off hand, it appears like MS wanted to get SQL into the XML lookup
picture. A good idea to leverage the database oriented developer
community.

How about a more "declarative" statement that takes most design
considerations into account?

Let Series equal list of "series" tags in document "TVShows.xml"
with preferred advanced reading options
Enable File Mapping if size over 500m bytes
FoundTagEvent = AddressOf FindEpsiodesPerSeries
FinishEvent = AddressOf GotAllSeries

and with ftors (functors) one can put the events in the statement too.

FoundTagEvent = function(item)
if item.cancel then
return false ' skips item
end if
return true
end function

and with refactoring, it can be added to application library:

series = MethodName("series","tvshows.xml")

<g>
 
Tom said:
I've not looked at the implementation of the .NET XPath classes - so, I can't
be sure how they are implemented. Though, there are basically two ways to
work with XML data, and that is DOM which loads the entire XML document model
into memory or using an XmlReader to stream the data. But, my comment had not
to do with that anyway. It was derived from comments made further up the
thread, where things like split and File.ReadAllLines were being discussed.

Right, thats was before the OP stated the XML details of what he was
doing. :)
As for the size of files being less of a concern... That must be very domain
specific, because it's something I have to worry about quite often - so I take
it seriously when I see entire files slurped up in one fell swoop in
production code :) I've seen servers brought to their knees from this
seemingly simple method of reading data.

I was speaking in general, dealing with larger files today is
generally not given a 2nd thought until one has system performance issues.
I'm not saying I never use stuff like File.ReadAllLines - but, I try to
carefully weigh the alternatives before I make this sort of decision.
right.
You think that XPath syntax is more straight forward then the simple statement
above? I'm not saying don't learn XPath, because there are times you need it
even with LINQ - but, LINQ is definately easier and more straight forward.

The above does look easy. I don't know LINQ, but in general, I am use
to the slash "/" path method, its more standardize method and it
directly applies to tag based data representations. Its used in other
technologies too, like CSS, DOM and now that Microsoft officially
supports jQuery in ASP.NET, XPATH DOM element look ups is supported. I
don't you will be able to use LINQ on the client side.
Anything is doable. But why reinvent the wheel? Use the tools that
LINQ is in .NET.

Thanks for highlighting LINQ as an alternative method.

I just looked up LINQ. For the general public, here is a good link:

http://msdn.microsoft.com/en-us/library/bb397897.aspx
Introduction to LINQ

Comparison of XPath and LINQ to XML
http://msdn.microsoft.com/en-us/library/bb675156.aspx

Is it for VS2008 and .NET 3.5 only?

Off hand, it appears like MS wanted to get SQL into the XML lookup
picture. A good idea to leverage the database oriented developer
community.

How about a more "declarative" statement that takes most design
considerations into account?

Let Series equal list of "series" tags in document "TVShows.xml"
with preferred advanced reading options
Enable File Mapping if size over 500m bytes
FoundTagEvent = AddressOf FindEpsiodesPerSeries
FinishEvent = AddressOf GotAllSeries

and with ftors (functors) one can put the events in the statement too.

FoundTagEvent = function(item)
if item.cancel then
return false ' skips item
end if
return true
end function

and with refactoring, it can be added to application library:

series = MethodName("series","tvshows.xml")

<g>
 
Yep come to think of it that is a small amount of data. The problem is my
main area of programming interest lies in writing applications for the
Nintendo DS console in c code. So I`m use to having to fight for every byte
of memory I can find :) I only started using VB.net a few weeks ago because
it was the easiest way to write windows applications, so I`ve still got a
lot to learn.

Rob
 
Yep come to think of it that is a small amount of data. The problem is my
main area of programming interest lies in writing applications for the
Nintendo DS console in c code. So I`m use to having to fight for every byte
of memory I can find :) I only started using VB.net a few weeks ago because
it was the easiest way to write windows applications, so I`ve still got a
lot to learn.

Rob
 
Back
Top