473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

what is wrong the following code?

I have following code, if you cut and paste it in VS and compile it
you see only an answer of 0. I was expecting values from o through
2999

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Resources;
using System.IO;
using System.Collections;

namespace ResourceTester
{
class Program
{
static void Main(string[] args)
{
//File.Delete("my.resources");
//FileStream fs = new FileStream("my.resources",
FileMode.CreateNew, FileAccess.Write, FileShare.Write, 1,
FileOptions.None);
//ResourceWriter rw = new ResourceWriter(fs);
//for (int i = 1; i < int.MaxValue; i++)
//{
// Console.WriteLine(i.ToString());
// rw.AddResource(i.ToString(),
"XXXXXXXXXXXXXXXXXXXXXXXXXXX" + i.ToString());
//}
//rw.Generate();
//rw.Close();
//fs.Dispose();
//fs.Close();

FileStream fs = new FileStream("my.resources",
FileMode.Create, FileAccess.Write);
IResourceWriter rw = new ResourceWriter(fs);

for(int i=0;i<3000;i++)
{
rw.AddResource(i.ToString(),
"VVVVVVVVVVVVVVVVVVVVVVVVVVV " + i.ToString());

if (i % 1000 == 0)
{
//generate and free resource writer<br>
rw.Generate();
rw.Close();

//free stream<br>
fs.Dispose();
fs.Close();

//reload file<br>
fs = new FileStream("my.resources",
FileMode.Append, FileAccess.Write);
rw = new ResourceWriter(fs);
}
}
//generate and free resource writer<br>
rw.Generate();
rw.Close();

//free stream<br>
fs.Dispose();
fs.Close();

FileStream fsa = new FileStream("my.resources",
FileMode.Open, FileAccess.Read);
IResourceReader rd = new ResourceReader(fsa);
IDictionaryEnumerator dict = rd.GetEnumerator();
while (dict.MoveNext())
{
Console.WriteLine(dict.Key);
}
}
}
}

Any help would be appreciated.

What I am trying to achive is to create a resource file of 3000
numbers, well I could very well directly write the data to the
resource, in reality I want to write all the way up to int.MaxValue.
But when I write, I run into 'Out of Memory' exception. So based on
the suggestion I was told to close and append the file stream, when I
do that at the end I can see the file size is increasing but when you
read the data, only the first file flush data is available.

Thanks.
Jun 28 '08 #1
6 1945
CSharper wrote:
I have following code, if you cut and paste it in VS and compile it
you see only an answer of 0. I was expecting values from o through
2999
<snip>
What I am trying to achive is to create a resource file of 3000
numbers, well I could very well directly write the data to the
resource, in reality I want to write all the way up to int.MaxValue.
But when I write, I run into 'Out of Memory' exception. So based on
the suggestion I was told to close and append the file stream, when I
do that at the end I can see the file size is increasing but when you
read the data, only the first file flush data is available.
I'm speculating here, but it's probably because the resource file has its
own "end of resources" marker embedded, so any data you append is simply
ignored. The only way to achieve this is to write the resources file in one
go, and you apparently can't do that because of the memory restriction.

Conceivably you could try to reverse-engineer or look up the format to
figure out a way to append the data without hitting this issue, but a far
more productive course of action would be to ask why on earth you want to
write 2,147,483,647 resource entries to a file. There's no problem with
having individual resources that are big, but how would you expect to make
effective use of that many different entries?

There is no requirement to use resource files to store data. If you don't
need it to be localizable, you're better off using your own files for very
particular data needs.

--
J.
Jun 28 '08 #2
On Jun 28, 11:40*am, Jeroen Mostert <jmost...@xs4all.nlwrote:
CSharper wrote:
I have following code, if you cut and paste it in VS and compile it
you see only an answer of 0. I was expecting values from o through
2999

<snip>
What I am trying to achive is to create a resource file of 3000
numbers, well I could very well directly write the data to the
resource, in reality I want to write all the way up to int.MaxValue.
But when I write, I run into 'Out of Memory' exception. So based on
the suggestion I was told to close and append the file stream, when I
do that at the end I can see the file size is increasing but when you
read the data, only the first file flush data is available.

I'm speculating here, but it's probably because the resource file has its
own "end of resources" marker embedded, so any data you append is simply
ignored. The only way to achieve this is to write the resources file in one
go, and you apparently can't do that because of the memory restriction.

Conceivably you could try to reverse-engineer or look up the format to
figure out a way to append the data without hitting this issue, but a far
more productive course of action would be to ask why on earth you want to
write 2,147,483,647 resource entries to a file. There's no problem with
having individual resources that are big, but how would you expect to make
effective use of that many different entries?

There is no requirement to use resource files to store data. If you don't
need it to be localizable, you're better off using your own files for very
particular data needs.

--
J.
thank you one reason I want to use the resource to use ILMERGE to
combine all the program, dll and resource files (required informaation
for the program inside the resource file) into one exe file. so I have
two questions
what can I use alternative to resource file to use as a resource in
ilmerge
or does anyone know what is the format or resource file so that I can
manually add?

Thanks.
Jun 28 '08 #3
CSharper wrote:
one reason I want to use the resource to use ILMERGE to
combine all the program, dll and resource files (required informaation
for the program inside the resource file) into one exe file.
I'm not familiar with ILMerge so I couldn't tell you how to use it in this
particular scenario, but I will say that you can compile resources into
separate satellite assemblies, which you could then conceivably merge with
ILMerge. See http://msdn.microsoft.com/library/21a15yht for more information
on that. Whether the program would still be able to find the resources that
are merged this way is another matter.
so I have two questions what can I use alternative to resource file to
use as a resource in ilmerge or does anyone know what is the format or
resource file so that I can manually add?
I wouldn't try manipulating .resources files manually; there's a reason the
framework offers a separate class for reading and writing them.

If you need more control over resource generation, you should use the .resx
format instead, since that's XML. You can compile .resx files into
..resources for embedding into assemblies with resgen.

--
J.
Jun 28 '08 #4
On Jun 28, 6:00*pm, Jeroen Mostert <jmost...@xs4all.nlwrote:
CSharper wrote:
one reason I want to use the resource to use ILMERGE to
combine all the program, dll and resource files (required informaation
for the program inside the resource file) into one exe file.

I'm not familiar with ILMerge so I couldn't tell you how to use it in this
particular scenario, but I will say that you can compile resources into
separate satellite assemblies, which you could then conceivably merge with
ILMerge. Seehttp://msdn.microsoft.com/library/21a15yhtfor more information
on that. Whether the program would still be able to find the resources that
are merged this way is another matter.
so I have two questions what can I use alternative to resource file to
use as a resource in ilmerge or does anyone know what is the format or
resource file so that I can manually add?

I wouldn't try manipulating .resources files manually; there's a reason the
framework offers a separate class for reading and writing them.

If you need more control over resource generation, you should use the .resx
format instead, since that's XML. You can compile .resx files into
.resources for embedding into assemblies with resgen.

--
J.
resx format, do you think, I will able to append data to it? I can't
find the constructor for it in C# 3.0, I thought it was
ResXResourceWriter???
Jun 29 '08 #5
DBC User wrote:
resx format, do you think, I will able to append data to it?
It's XML, so you can't just append at the end -- but since XML is an open
format, you can rewrite these files in any number of ways that don't run
into memory problems. You can't do the same for .resources files because you
don't know the format.
I can't find the constructor for it in C# 3.0, I thought it was
ResXResourceWriter???
It's in System.Windows.Forms, but the class will probably not be of much use
to you, since it cannot be used to append data any more than ResourceWriter
can. What you can do is stream the XML data in and write it out to a new
file until you hit the end, then write out your new resources. This requires
no additional memory.

Please note that if all you want to do is merge resource files and you don't
actually have a memory problem (only the pathological one you created
yourself by going for MaxInt entries) then the problem is much more cleanly
solved by using ResourceWriter or ResXResourceWriter. Read the resources
from one file, read the resources from the second file, add the resources
from the second file to the resources of the first file, write out the new
resource file. It seems unlikely to me that you'd run into memory problems
unless the resource files were already very large to begin with, but if
that's the case then the merged resource file would probably not be loadable.

--
J.
Jun 29 '08 #6
On Jun 29, 3:16*am, Jeroen Mostert <jmost...@xs4all.nlwrote:
DBC User wrote:
resx format, do you think, I will able to append data to it?

It's XML, so you can't just append at the end -- but since XML is an open
format, you can rewrite these files in any number of ways that don't run
into memory problems. You can't do the same for .resources files because you
don't know the format.
I can't find the constructor for it in C# 3.0, I thought it was
ResXResourceWriter???

It's in System.Windows.Forms, but the class will probably not be of much use
to you, since it cannot be used to append data any more than ResourceWriter
can. What you can do is stream the XML data in and write it out to a new
file until you hit the end, then write out your new resources. This requires
no additional memory.

Please note that if all you want to do is merge resource files and you don't
actually have a memory problem (only the pathological one you created
yourself by going for MaxInt entries) then the problem is much more cleanly
solved by using ResourceWriter or ResXResourceWriter. Read the resources
from one file, read the resources from the second file, add the resources
from the second file to the resources of the first file, write out the new
resource file. It seems unlikely to me that you'd run into memory problems
unless the resource files were already very large to begin with, but if
that's the case then the merged resource file would probably not be loadable.

--
J.
Thanks, I went back to resources and instead of creating single
resource files, I have created multiple resource files and during the
lookup, if I don't find it in one resource I switch to another
resource and it works with one caviat. I ran csc to build the project
with all these resources and it compiled and created the exe file. At
the end, I ran ILMerge to build one exe file with other dls I use in
the project, ILMerge fails with Out Of Memory. Now I need to find out,
if there is an alternate way to include the depened dlls in a single
exe using csc/al.exe
Jun 30 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
10
by: Greener | last post by:
Hi, I need help badly. Can you do client-side programming instead of server-side to capture the Browser type info? If this is the case, what's wrong with the following? <script...
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
17
by: Paul | last post by:
HI! I get an error with this code. <SCRIPT language="JavaScript"> If (ifp==""){ ifp="default.htm"} //--></SCRIPT> Basicly I want my iframe to have a default page if the user enters in...
56
by: Cherrish Vaidiyan | last post by:
Frinds, Hope everyone is doing fine.i feel pointers to be the most toughest part in C. i have just completed learning pointers & arrays related portions. I need to attend technical interview on...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
3
by: Terry Olsen | last post by:
I've got 2 different web pages, both updating the same SQL database. One is for the Technician and one is for the Manager. The technician's update page works fine but the Manager's update page...
98
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
4
by: grizggg | last post by:
I have searched and not found an answer to this question. I ran upon the following statement in a *.cpp file in a member function: static const char * const pacz_HTMLContentTypeHeader =...
7
by: mosfet | last post by:
HI, when trying to compile an embedded version of STL called ustl on win32 platform I get the following error : /// Returns the minimum of \p a and \p b template <typename T1, typename T2>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.