By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,297 Members | 1,383 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,297 IT Pros & Developers. It's quick & easy.

How to share embedded resource?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.