473,941 Members | 16,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Collecti ons.Generic;
using System.Linq;
using System.Text;
using System.Resource s;
using System.IO;
using System.Collecti ons;

namespace ResourceTester
{
class Program
{
static void Main(string[] args)
{
//File.Delete("my .resources");
//FileStream fs = new FileStream("my. resources",
FileMode.Create New, FileAccess.Writ e, FileShare.Write , 1,
FileOptions.Non e);
//ResourceWriter rw = new ResourceWriter( fs);
//for (int i = 1; i < int.MaxValue; i++)
//{
// Console.WriteLi ne(i.ToString() );
// rw.AddResource( i.ToString(),
"XXXXXXXXXXXXXX XXXXXXXXXXXXX" + i.ToString());
//}
//rw.Generate();
//rw.Close();
//fs.Dispose();
//fs.Close();

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

for(int i=0;i<3000;i++)
{
rw.AddResource( i.ToString(),
"VVVVVVVVVVVVVV VVVVVVVVVVVVV " + 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.Writ e);
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);
IDictionaryEnum erator dict = rd.GetEnumerato r();
while (dict.MoveNext( ))
{
Console.WriteLi ne(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 1973
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...@xs4al l.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...@xs4al l.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
ResXResourceWri ter???
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
ResXResourceWri ter???
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 ResXResourceWri ter. 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...@xs4al l.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
ResXResourceWri ter???

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 ResXResourceWri ter. 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
14986
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 software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
10
3432
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 language="JavaScript"> function doWord(file) { if (navigator.userAgent.indexOf("MSIE")!=-1)
72
5947
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 example, between a C/C++ programmers with a few weeks of experience and a C/C++ programmer with years of experience. You don't really need to understand the subtle details or use the obscure features of either language
17
2669
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 directly. so I need a way doing this. so I check to see if the ifp value is null and if so then assign it a value. is this correct?
56
4444
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 C. wat type of questions should be expected? Which part of C language do the staff give more concern? The interviewers have just mentioned that .. i will have interview on C. Also can anyone can help me with sites where i can go thru sample
13
5083
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
1557
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 doesn't. They are both the same..as far as I can tell... --------------------- This code works fine, updating the SQL database with the edited data. Code for Tech Page
98
4680
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
6711
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 = "Content-Type: text/html\r\n"; Why is the second const needed and what does it do? Thanks
7
4280
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> inline const T1 min (const T1& a, const T2& b) { return (a < b ? a : b);
0
9964
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11530
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11295
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10659
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9858
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7389
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6298
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3506
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.