473,396 Members | 2,004 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,396 software developers and data experts.

How to share embedded resource?

I am making a DLL that has a class that will be made into
several similar objects for the user. I have a .gif file that
has all the parts those objects need. I am wondering what
the proper way to share that image across all the objects is
so I don't end up with that single .gif loaded multiple times.

I am thinking I should make a Friend class that has a shared
property that returns the image, but I want to be sure it is
returned ByRef, and not ByVal, or otherwise copied for
every call. The .gif file itself is an embeded resource and
I am thinking if I create it through the GetManifestResourceStream
method each time it is needed, then each time I'll be making
a copy of the same image.

What is the 'pattern' for this situation, and does anyone know
of a link to a VB.NET example?

Thanks!
LFS
Nov 20 '05 #1
3 1349
Hi, Larry

You can use shared member to keep reference to gif. If it is loaded as Image
or PictureBox, or another object, you will pass only reference. By default
all objects are passed ByRef - you don't need to worry about this. Just load
gif once, for example, during first call - see singleton pattern, it's what
you need.

HTH
Alex

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
I am making a DLL that has a class that will be made into
several similar objects for the user. I have a .gif file that
has all the parts those objects need. I am wondering what
the proper way to share that image across all the objects is
so I don't end up with that single .gif loaded multiple times.

I am thinking I should make a Friend class that has a shared
property that returns the image, but I want to be sure it is
returned ByRef, and not ByVal, or otherwise copied for
every call. The .gif file itself is an embeded resource and
I am thinking if I create it through the GetManifestResourceStream
method each time it is needed, then each time I'll be making
a copy of the same image.

What is the 'pattern' for this situation, and does anyone know
of a link to a VB.NET example?

Thanks!
LFS

Nov 20 '05 #2
A singleton pattern can be enforced by using a shared property to return the
GIF image.
Property Get statements are really compiled under the covers as a method,
and all method return values are ByRef anyway, so you don't have to worry
about that. But for reference types, even ByVal doesn't copy objects, only
the object reference (pointer). You may end up with several object refrences
in that case, but they all point at the same blob of data.

-Rob Teixeira [MVP]

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
I am making a DLL that has a class that will be made into
several similar objects for the user. I have a .gif file that
has all the parts those objects need. I am wondering what
the proper way to share that image across all the objects is
so I don't end up with that single .gif loaded multiple times.

I am thinking I should make a Friend class that has a shared
property that returns the image, but I want to be sure it is
returned ByRef, and not ByVal, or otherwise copied for
every call. The .gif file itself is an embeded resource and
I am thinking if I create it through the GetManifestResourceStream
method each time it is needed, then each time I'll be making
a copy of the same image.

What is the 'pattern' for this situation, and does anyone know
of a link to a VB.NET example?

Thanks!
LFS

Nov 20 '05 #3

"Larry Serflaten" <se*******@usinternet.com> wrote
I am making a DLL that has a class that will be made into
several similar objects for the user. ....


Thanks guys, I'll use the Singleton pattern, I just wanted to
get validation on the proper method so I don't have to waste
time testing for excessive memory use. With GC its all so
unfamiliar, I didn't know if I could tell the difference between
multiple 'streams' or just the GC (garbage collector) falling
behind!

<g>
LFS
Nov 20 '05 #4

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

Similar topics

1
by: james | last post by:
What class / method should I be using to get the full path to an embedded resource ? In my case I have an .xml file that my app uses, it is set as embedded resource, and I have a control that...
5
by: Drew | last post by:
Assembly asm = Assembly.GetExecutingAssembly(); me = new Bitmap(asm.GetManifestResourceStream("me.gif")); I have used this before without any problem, but now I get: An unhandled exception...
1
by: n! | last post by:
I have an irritating problem with VS.NET2003, C#. I wrote some code that would build my application menu from an XML resource file. Purely to make it easy for me to edit, so I've added this file as...
2
by: Kyle Kaitan | last post by:
I have an assembly (AppResources.dll) which contains a number of embedded resource files. Most of these are key/value pairs of relevant strings; a few are images and sounds; some more are XML...
0
by: Johann Blake | last post by:
I'm having trouble grasping how ASP.NET correctly locates resources. There is plenty of documentation on this subject but some things are not clear at all. In my ASP.NET application, I have...
2
by: yxq | last post by:
Hello I want to create and delete the folder share, i found that it is ok for generic folder, but it does not work for Root directory(i.e c:\, d:\) The code...
4
by: Jason Pettys | last post by:
In an ASP.NET project I am setting the content type of my .ascx and ..aspx files to Embedded Resource for a separate reason. When I do this they get embedded as "RootNamespace.Filename" but I...
2
Frinavale
by: Frinavale | last post by:
I am attempting to use embedded resources in an Ajax Enabled ASP.NET Web Application. I'm using Visual Studio 2008 and VB.NET server side code. The project is called "EmbeddedResources" with the...
2
by: steve | last post by:
I have the following routine for retrieving error message strigs from a resource file which is embedded in the project. But when it is called I get the error messsage "Could not find any...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...

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.