473,568 Members | 3,014 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Enum memory allocation

Regarding use of enum's, I am wondering what the cost of memory is when creating the enumeration on the calling side, and then using it on the function/method side. See example below. If I understand correctly, what is actually happening on the calling side is an instance of the enum class FavoriteSport is getting created and sent to the PrintFavorite routine with a default value of type int. Is this correct? Say I have a couple hundred uses of this enumeration at the same time (Citrix server for a Statewide application), would I have a couple hundred or more instances of this enum class in memory

I'm still trying to understand .Net and the true object oriented nature of how it works now, so any information would be greatly appreciated

Thanks

Michael Isaac

public enum FavoriteSpor
Basebal
Socce
end enu

Public Sub PrintFavorite(B yVal intFavorite as FavoriteSport
Select Case intFavorite ..
'if Baseball print "I Love baseball" , et
End Su

'calling pro
PrintFavorite(F avoriteSport.So ccer
Nov 20 '05 #1
6 2865
"Michael Isaacs" <an*******@disc ussions.microso ft.com> wrote in message news:87******** *************** ***********@mic rosoft.com...
Regarding use of enum's, I am wondering what the cost of memory is : an instance of the enum class FavoriteSport is getting created and sent
to the PrintFavorite routine with a default value of type int. Is this correct?
An Enum is a Structure (extending ValueType), and not a Class. Therefore,
there is no explicit creation on the heap for this memory. Instead, it is a field
within a Class, or it exists temporarily on the stack as a local variable.

The cost is typically 4 bytes. Due to 32-bit word alignment, there's usually
little benefit in assiging a smaller numeric type to the Enum (more Enums,
but they're slower to access.)
Say I have a couple hundred uses of this enumeration at the same time
(Citrix server for a Statewide application), would I have a couple hundred
or more instances of this enum class in memory?
You'll have copies of an integer (or perhaps byte, long, etc.) throughout
memory and on the stack. (Although to highlight the magnitude of this
memory consumption, observe that my PDA can hold up to 16 million
enums; hopefully the server for your app is larger than my PDA.)

: : public enum FavoriteSport
Baseball
Soccer
end enum

Public Sub PrintFavorite(B yVal intFavorite as FavoriteSport)
4 bytes are pushed onto the stack to contain intFavorite, and the
value of this argument has its value copied to it from the calling Sub.
Select Case intFavorite ...
'if Baseball print "I Love baseball" , etc
End Sub

'calling proc
PrintFavorite(F avoriteSport.So ccer)


As this is passing a constant argument, I believe the 4 bytes are pushed
directly onto the stack of the called Sub. Contrast this to,

Dim sport As FavoriteSport = FavoriteSport.S occer
PrintFavorite( sport)

Which has a 4-byte copy of the Enum in the calling Sub, and pushes a 4-byte
copy of the Enum to the called Sub. Hence, here memory consumption is
8-bytes.

Also observe that both Enums are stored on the stack automatically, and when
each Sub ends, the stack rolls back and the memory consumed by these Enums
are returned to the system W/O requiring a garbage collection.

Their drawback, if any, is all the copying that takes place. But, it doesn't get
any faster than copying four-bytes at a time (at least on 32-bit machines), so
this is ordinarily insignificant.
Derek Harmon
Nov 20 '05 #2
Thanks - this was very informative to me. Follow up questions ...

The question that then comes up is how VB knows that this is an enum object
if it is only stored as an integer in memory? Ie. how does it know that it
has methods, functions, etc? My manager is concerned that even if only 4
bytes are being sent in to the function, that the function is still creating
some kind of object that allows for these methods, properties, etc to be
accessed.

Also, is there any Microsoft documentation out there that explains this, or
a good web site that anyone knows about?

Thanks,

Mike

"Derek Harmon" <lo*******@msn. com> wrote in message
news:uk******** ******@TK2MSFTN GP10.phx.gbl...
"Michael Isaacs" <an*******@disc ussions.microso ft.com> wrote in message news:87******** *************** ***********@mic rosoft.com...
Regarding use of enum's, I am wondering what the cost of memory is

:
an instance of the enum class FavoriteSport is getting created and sent
to the PrintFavorite routine with a default value of type int. Is this correct?
An Enum is a Structure (extending ValueType), and not a Class. Therefore,
there is no explicit creation on the heap for this memory. Instead, it is a field within a Class, or it exists temporarily on the stack as a local variable.

The cost is typically 4 bytes. Due to 32-bit word alignment, there's usually little benefit in assiging a smaller numeric type to the Enum (more Enums,
but they're slower to access.)
Say I have a couple hundred uses of this enumeration at the same time
(Citrix server for a Statewide application), would I have a couple
hundred or more instances of this enum class in memory?


You'll have copies of an integer (or perhaps byte, long, etc.) throughout
memory and on the stack. (Although to highlight the magnitude of this
memory consumption, observe that my PDA can hold up to 16 million
enums; hopefully the server for your app is larger than my PDA.)

: :
public enum FavoriteSport
Baseball
Soccer
end enum

Public Sub PrintFavorite(B yVal intFavorite as FavoriteSport)


4 bytes are pushed onto the stack to contain intFavorite, and the
value of this argument has its value copied to it from the calling Sub.
Select Case intFavorite ...
'if Baseball print "I Love baseball" , etc
End Sub

'calling proc
PrintFavorite(F avoriteSport.So ccer)


As this is passing a constant argument, I believe the 4 bytes are pushed
directly onto the stack of the called Sub. Contrast this to,

Dim sport As FavoriteSport = FavoriteSport.S occer
PrintFavorite( sport)

Which has a 4-byte copy of the Enum in the calling Sub, and pushes a

4-byte copy of the Enum to the called Sub. Hence, here memory consumption is
8-bytes.

Also observe that both Enums are stored on the stack automatically, and when each Sub ends, the stack rolls back and the memory consumed by these Enums
are returned to the system W/O requiring a garbage collection.

Their drawback, if any, is all the copying that takes place. But, it doesn't get any faster than copying four-bytes at a time (at least on 32-bit machines), so this is ordinarily insignificant.
Derek Harmon

Nov 20 '05 #3
Michael,
The question that then comes up is how VB knows that this is an enum object if it is only stored as an integer in memory? You know it is an enum object by virtual you defined it as an Enum type.
Ie. how does it know that it has methods, functions, etc? The compiler sees that it is of type FavoriteSport and knows that
FavoriteSport and acts accordingly.
My manager is concerned that even if only 4
bytes are being sent in to the function, that the function is still creating some kind of object that allows for these methods, properties, etc to be
accessed. Unfortunately this is a common misunderstandin g, the compiler knows that an
Integer has certain methods and is able to call the methods directly. It
knows that an FavoriteSport has certain methods & is able to call those
directly. The only time a FavoriteSport would be "creating some kind of
object" Object in the sense that it is on the heap, is when you pass it as
an System.Object, System.Enum, System.ValueTyp e or an Interface parameter.
Most of the time you do not/should not do this.
Also, is there any Microsoft documentation out there that explains this, or a good web site that anyone knows about? "The Common Language Infrastructure Annotated Standard" by James S. Miller,
from Addison Wesley. The Common Language Infrastructure Standard itself (non
annotated) is available on your harddisk when you install the SDK, for
VS.NET 2003 its at "\Program Files\Microsoft Visual Studio .NET
2003\SDK\v1.1\T ool Developers Guide\docs". Primarily read up on the
difference of Reference Types & Value Types.

Hope this helps
Jay
"Michael Isaacs" <ms*******@isaa csonline.org.no moresmp> wrote in message
news:eB******** ******@TK2MSFTN GP12.phx.gbl... Thanks - this was very informative to me. Follow up questions ...

The question that then comes up is how VB knows that this is an enum object if it is only stored as an integer in memory? Ie. how does it know that it has methods, functions, etc? My manager is concerned that even if only 4
bytes are being sent in to the function, that the function is still creating some kind of object that allows for these methods, properties, etc to be
accessed.

Also, is there any Microsoft documentation out there that explains this, or a good web site that anyone knows about?

Thanks,

Mike

"Derek Harmon" <lo*******@msn. com> wrote in message
news:uk******** ******@TK2MSFTN GP10.phx.gbl...
"Michael Isaacs" <an*******@disc ussions.microso ft.com> wrote in message news:87******** *************** ***********@mic rosoft.com...
Regarding use of enum's, I am wondering what the cost of memory is

:
an instance of the enum class FavoriteSport is getting created and sent to the PrintFavorite routine with a default value of type int. Is
this correct?

An Enum is a Structure (extending ValueType), and not a Class. Therefore, there is no explicit creation on the heap for this memory. Instead, it is
a field
within a Class, or it exists temporarily on the stack as a local

variable.
The cost is typically 4 bytes. Due to 32-bit word alignment, there's

usually
little benefit in assiging a smaller numeric type to the Enum (more Enums, but they're slower to access.)
Say I have a couple hundred uses of this enumeration at the same time
(Citrix server for a Statewide application), would I have a couple hundred or more instances of this enum class in memory?


You'll have copies of an integer (or perhaps byte, long, etc.)

throughout memory and on the stack. (Although to highlight the magnitude of this
memory consumption, observe that my PDA can hold up to 16 million
enums; hopefully the server for your app is larger than my PDA.)

: :
public enum FavoriteSport
Baseball
Soccer
end enum

Public Sub PrintFavorite(B yVal intFavorite as FavoriteSport)


4 bytes are pushed onto the stack to contain intFavorite, and the
value of this argument has its value copied to it from the calling Sub.
Select Case intFavorite ...
'if Baseball print "I Love baseball" , etc
End Sub

'calling proc
PrintFavorite(F avoriteSport.So ccer)


As this is passing a constant argument, I believe the 4 bytes are pushed
directly onto the stack of the called Sub. Contrast this to,

Dim sport As FavoriteSport = FavoriteSport.S occer
PrintFavorite( sport)

Which has a 4-byte copy of the Enum in the calling Sub, and pushes a

4-byte
copy of the Enum to the called Sub. Hence, here memory consumption is
8-bytes.

Also observe that both Enums are stored on the stack automatically, and

when
each Sub ends, the stack rolls back and the memory consumed by these Enums are returned to the system W/O requiring a garbage collection.

Their drawback, if any, is all the copying that takes place. But, it

doesn't get
any faster than copying four-bytes at a time (at least on 32-bit

machines), so
this is ordinarily insignificant.
Derek Harmon


Nov 20 '05 #4
Michael,
The question that then comes up is how VB knows that this is an enum object if it is only stored as an integer in memory? You know it is an enum object by virtual you defined it as an Enum type.
Ie. how does it know that it has methods, functions, etc? The compiler sees that it is of type FavoriteSport and knows that
FavoriteSport and acts accordingly.
My manager is concerned that even if only 4
bytes are being sent in to the function, that the function is still creating some kind of object that allows for these methods, properties, etc to be
accessed. Unfortunately this is a common misunderstandin g, the compiler knows that an
Integer has certain methods and is able to call the methods directly. It
knows that an FavoriteSport has certain methods & is able to call those
directly. The only time a FavoriteSport would be "creating some kind of
object" Object in the sense that it is on the heap, is when you pass it as
an System.Object, System.Enum, System.ValueTyp e or an Interface parameter.
Most of the time you do not/should not do this.
Also, is there any Microsoft documentation out there that explains this, or a good web site that anyone knows about? "The Common Language Infrastructure Annotated Standard" by James S. Miller,
from Addison Wesley. The Common Language Infrastructure Standard itself (non
annotated) is available on your harddisk when you install the SDK, for
VS.NET 2003 its at "\Program Files\Microsoft Visual Studio .NET
2003\SDK\v1.1\T ool Developers Guide\docs". Primarily read up on the
difference of Reference Types & Value Types.

Hope this helps
Jay
"Michael Isaacs" <ms*******@isaa csonline.org.no moresmp> wrote in message
news:eB******** ******@TK2MSFTN GP12.phx.gbl... Thanks - this was very informative to me. Follow up questions ...

The question that then comes up is how VB knows that this is an enum object if it is only stored as an integer in memory? Ie. how does it know that it has methods, functions, etc? My manager is concerned that even if only 4
bytes are being sent in to the function, that the function is still creating some kind of object that allows for these methods, properties, etc to be
accessed.

Also, is there any Microsoft documentation out there that explains this, or a good web site that anyone knows about?

Thanks,

Mike

"Derek Harmon" <lo*******@msn. com> wrote in message
news:uk******** ******@TK2MSFTN GP10.phx.gbl...
"Michael Isaacs" <an*******@disc ussions.microso ft.com> wrote in message news:87******** *************** ***********@mic rosoft.com...
Regarding use of enum's, I am wondering what the cost of memory is

:
an instance of the enum class FavoriteSport is getting created and sent to the PrintFavorite routine with a default value of type int. Is
this correct?

An Enum is a Structure (extending ValueType), and not a Class. Therefore, there is no explicit creation on the heap for this memory. Instead, it is
a field
within a Class, or it exists temporarily on the stack as a local

variable.
The cost is typically 4 bytes. Due to 32-bit word alignment, there's

usually
little benefit in assiging a smaller numeric type to the Enum (more Enums, but they're slower to access.)
Say I have a couple hundred uses of this enumeration at the same time
(Citrix server for a Statewide application), would I have a couple hundred or more instances of this enum class in memory?


You'll have copies of an integer (or perhaps byte, long, etc.)

throughout memory and on the stack. (Although to highlight the magnitude of this
memory consumption, observe that my PDA can hold up to 16 million
enums; hopefully the server for your app is larger than my PDA.)

: :
public enum FavoriteSport
Baseball
Soccer
end enum

Public Sub PrintFavorite(B yVal intFavorite as FavoriteSport)


4 bytes are pushed onto the stack to contain intFavorite, and the
value of this argument has its value copied to it from the calling Sub.
Select Case intFavorite ...
'if Baseball print "I Love baseball" , etc
End Sub

'calling proc
PrintFavorite(F avoriteSport.So ccer)


As this is passing a constant argument, I believe the 4 bytes are pushed
directly onto the stack of the called Sub. Contrast this to,

Dim sport As FavoriteSport = FavoriteSport.S occer
PrintFavorite( sport)

Which has a 4-byte copy of the Enum in the calling Sub, and pushes a

4-byte
copy of the Enum to the called Sub. Hence, here memory consumption is
8-bytes.

Also observe that both Enums are stored on the stack automatically, and

when
each Sub ends, the stack rolls back and the memory consumed by these Enums are returned to the system W/O requiring a garbage collection.

Their drawback, if any, is all the copying that takes place. But, it

doesn't get
any faster than copying four-bytes at a time (at least on 32-bit

machines), so
this is ordinarily insignificant.
Derek Harmon


Nov 20 '05 #5
Thanks Jay.

I also did a test using enum objects and checking memory usage to confirm
that enum objects only take the amount of memory of the base type (default
integer = 4 bytes). This satisfied my manager on the subject. Also, good
point about integers and the comparison between integer variables and
enums - both do have methods, etc, but are both stored as 4 bytes when used.

Michael Isaacs
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:ux******** ******@TK2MSFTN GP11.phx.gbl...
Michael,
The question that then comes up is how VB knows that this is an enum object
if it is only stored as an integer in memory?

You know it is an enum object by virtual you defined it as an Enum type.
Ie. how does it know that it has methods, functions, etc?

The compiler sees that it is of type FavoriteSport and knows that
FavoriteSport and acts accordingly.
My manager is concerned that even if only 4
bytes are being sent in to the function, that the function is still

creating
some kind of object that allows for these methods, properties, etc to be
accessed.

Unfortunately this is a common misunderstandin g, the compiler knows that

an Integer has certain methods and is able to call the methods directly. It
knows that an FavoriteSport has certain methods & is able to call those
directly. The only time a FavoriteSport would be "creating some kind of
object" Object in the sense that it is on the heap, is when you pass it as
an System.Object, System.Enum, System.ValueTyp e or an Interface parameter.
Most of the time you do not/should not do this.
Also, is there any Microsoft documentation out there that explains this, or
a good web site that anyone knows about?

"The Common Language Infrastructure Annotated Standard" by James S.

Miller, from Addison Wesley. The Common Language Infrastructure Standard itself (non annotated) is available on your harddisk when you install the SDK, for
VS.NET 2003 its at "\Program Files\Microsoft Visual Studio .NET
2003\SDK\v1.1\T ool Developers Guide\docs". Primarily read up on the
difference of Reference Types & Value Types.

Hope this helps
Jay
"Michael Isaacs" <ms*******@isaa csonline.org.no moresmp> wrote in message
news:eB******** ******@TK2MSFTN GP12.phx.gbl...
Thanks - this was very informative to me. Follow up questions ...

The question that then comes up is how VB knows that this is an enum object
if it is only stored as an integer in memory? Ie. how does it know that

it
has methods, functions, etc? My manager is concerned that even if only 4
bytes are being sent in to the function, that the function is still

creating
some kind of object that allows for these methods, properties, etc to be
accessed.

Also, is there any Microsoft documentation out there that explains this,

or
a good web site that anyone knows about?

Thanks,

Mike

"Derek Harmon" <lo*******@msn. com> wrote in message
news:uk******** ******@TK2MSFTN GP10.phx.gbl...
"Michael Isaacs" <an*******@disc ussions.microso ft.com> wrote in message
news:87******** *************** ***********@mic rosoft.com...
> Regarding use of enum's, I am wondering what the cost of memory is
:
> an instance of the enum class FavoriteSport is getting created and sent > to the PrintFavorite routine with a default value of type int. Is this
correct?

An Enum is a Structure (extending ValueType), and not a Class.

Therefore, there is no explicit creation on the heap for this memory. Instead,
it is
a field
within a Class, or it exists temporarily on the stack as a local

variable.
The cost is typically 4 bytes. Due to 32-bit word alignment, there's

usually
little benefit in assiging a smaller numeric type to the Enum (more Enums, but they're slower to access.)

> Say I have a couple hundred uses of this enumeration at the same
time > (Citrix server for a Statewide application), would I have a couple

hundred
> or more instances of this enum class in memory?

You'll have copies of an integer (or perhaps byte, long, etc.)

throughout memory and on the stack. (Although to highlight the magnitude of this
memory consumption, observe that my PDA can hold up to 16 million
enums; hopefully the server for your app is larger than my PDA.)

: :
> public enum FavoriteSport
> Baseball
> Soccer
> end enum
>
> Public Sub PrintFavorite(B yVal intFavorite as FavoriteSport)

4 bytes are pushed onto the stack to contain intFavorite, and the
value of this argument has its value copied to it from the calling Sub.
> Select Case intFavorite ...
> 'if Baseball print "I Love baseball" , etc
> End Sub
>
> 'calling proc
> PrintFavorite(F avoriteSport.So ccer)

As this is passing a constant argument, I believe the 4 bytes are pushed directly onto the stack of the called Sub. Contrast this to,

Dim sport As FavoriteSport = FavoriteSport.S occer
PrintFavorite( sport)

Which has a 4-byte copy of the Enum in the calling Sub, and pushes a

4-byte
copy of the Enum to the called Sub. Hence, here memory consumption is
8-bytes.

Also observe that both Enums are stored on the stack automatically,
and when
each Sub ends, the stack rolls back and the memory consumed by these

Enums are returned to the system W/O requiring a garbage collection.

Their drawback, if any, is all the copying that takes place. But, it

doesn't get
any faster than copying four-bytes at a time (at least on 32-bit

machines), so
this is ordinarily insignificant.
Derek Harmon



Nov 20 '05 #6
Thanks Jay.

I also did a test using enum objects and checking memory usage to confirm
that enum objects only take the amount of memory of the base type (default
integer = 4 bytes). This satisfied my manager on the subject. Also, good
point about integers and the comparison between integer variables and
enums - both do have methods, etc, but are both stored as 4 bytes when used.

Michael Isaacs
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:ux******** ******@TK2MSFTN GP11.phx.gbl...
Michael,
The question that then comes up is how VB knows that this is an enum object
if it is only stored as an integer in memory?

You know it is an enum object by virtual you defined it as an Enum type.
Ie. how does it know that it has methods, functions, etc?

The compiler sees that it is of type FavoriteSport and knows that
FavoriteSport and acts accordingly.
My manager is concerned that even if only 4
bytes are being sent in to the function, that the function is still

creating
some kind of object that allows for these methods, properties, etc to be
accessed.

Unfortunately this is a common misunderstandin g, the compiler knows that

an Integer has certain methods and is able to call the methods directly. It
knows that an FavoriteSport has certain methods & is able to call those
directly. The only time a FavoriteSport would be "creating some kind of
object" Object in the sense that it is on the heap, is when you pass it as
an System.Object, System.Enum, System.ValueTyp e or an Interface parameter.
Most of the time you do not/should not do this.
Also, is there any Microsoft documentation out there that explains this, or
a good web site that anyone knows about?

"The Common Language Infrastructure Annotated Standard" by James S.

Miller, from Addison Wesley. The Common Language Infrastructure Standard itself (non annotated) is available on your harddisk when you install the SDK, for
VS.NET 2003 its at "\Program Files\Microsoft Visual Studio .NET
2003\SDK\v1.1\T ool Developers Guide\docs". Primarily read up on the
difference of Reference Types & Value Types.

Hope this helps
Jay
"Michael Isaacs" <ms*******@isaa csonline.org.no moresmp> wrote in message
news:eB******** ******@TK2MSFTN GP12.phx.gbl...
Thanks - this was very informative to me. Follow up questions ...

The question that then comes up is how VB knows that this is an enum object
if it is only stored as an integer in memory? Ie. how does it know that

it
has methods, functions, etc? My manager is concerned that even if only 4
bytes are being sent in to the function, that the function is still

creating
some kind of object that allows for these methods, properties, etc to be
accessed.

Also, is there any Microsoft documentation out there that explains this,

or
a good web site that anyone knows about?

Thanks,

Mike

"Derek Harmon" <lo*******@msn. com> wrote in message
news:uk******** ******@TK2MSFTN GP10.phx.gbl...
"Michael Isaacs" <an*******@disc ussions.microso ft.com> wrote in message
news:87******** *************** ***********@mic rosoft.com...
> Regarding use of enum's, I am wondering what the cost of memory is
:
> an instance of the enum class FavoriteSport is getting created and sent > to the PrintFavorite routine with a default value of type int. Is this
correct?

An Enum is a Structure (extending ValueType), and not a Class.

Therefore, there is no explicit creation on the heap for this memory. Instead,
it is
a field
within a Class, or it exists temporarily on the stack as a local

variable.
The cost is typically 4 bytes. Due to 32-bit word alignment, there's

usually
little benefit in assiging a smaller numeric type to the Enum (more Enums, but they're slower to access.)

> Say I have a couple hundred uses of this enumeration at the same
time > (Citrix server for a Statewide application), would I have a couple

hundred
> or more instances of this enum class in memory?

You'll have copies of an integer (or perhaps byte, long, etc.)

throughout memory and on the stack. (Although to highlight the magnitude of this
memory consumption, observe that my PDA can hold up to 16 million
enums; hopefully the server for your app is larger than my PDA.)

: :
> public enum FavoriteSport
> Baseball
> Soccer
> end enum
>
> Public Sub PrintFavorite(B yVal intFavorite as FavoriteSport)

4 bytes are pushed onto the stack to contain intFavorite, and the
value of this argument has its value copied to it from the calling Sub.
> Select Case intFavorite ...
> 'if Baseball print "I Love baseball" , etc
> End Sub
>
> 'calling proc
> PrintFavorite(F avoriteSport.So ccer)

As this is passing a constant argument, I believe the 4 bytes are pushed directly onto the stack of the called Sub. Contrast this to,

Dim sport As FavoriteSport = FavoriteSport.S occer
PrintFavorite( sport)

Which has a 4-byte copy of the Enum in the calling Sub, and pushes a

4-byte
copy of the Enum to the called Sub. Hence, here memory consumption is
8-bytes.

Also observe that both Enums are stored on the stack automatically,
and when
each Sub ends, the stack rolls back and the memory consumed by these

Enums are returned to the system W/O requiring a garbage collection.

Their drawback, if any, is all the copying that takes place. But, it

doesn't get
any faster than copying four-bytes at a time (at least on 32-bit

machines), so
this is ordinarily insignificant.
Derek Harmon



Nov 20 '05 #7

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

Similar topics

6
8186
by: chris | last post by:
Hi all, I need to know, what is the difference between dynamic memory allocation, and stack allocation ? 1. If I have a class named DestinationAddress, when should I use dynamic memory allocation to create object of that class ? 2. If it says "dynamic memory allocation", is it mean the following code : DestinationAddress* dest = new...
5
274
by: Michael Isaacs | last post by:
Regarding use of enum's, I am wondering what the cost of memory is when creating the enumeration on the calling side, and then using it on the function/method side. See example below. If I understand correctly, what is actually happening on the calling side is an instance of the enum class FavoriteSport is getting created and sent to the...
62
17673
by: ivan.leben | last post by:
How can I really delete a preloaded image from memory/disk cache? Let's say I preload an image by creating an Image object and setting its src attribute to desired URL: var img = new Image(); img.src = ; Then I use the image a few more times by adding it into an Array object:
66
3576
by: Johan Tibell | last post by:
I've written a piece of code that uses sockets a lot (I know that sockets aren't portable C, this is not a question about sockets per se). Much of my code ended up looking like this: if (function(socket, args) == -1) { perror("function"); exit(EXIT_FAILURE); } I feel that the ifs destroy the readability of my code. Would it be
34
11150
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code snippet that I wrote today that gives me an instant implementation of the pattern. I could easily just always use such an implementation instead of a...
24
19045
by: Ken | last post by:
In C programming, I want to know in what situations we should use static memory allocation instead of dynamic memory allocation. My understanding is that static memory allocation like using array is faster than malloc, but dynamic memory allocation is more flexible. Please comment... thanks.
1
7953
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was compiled and run without any erros but the second program has a run time error when the function return from allocate and the ptr become NULL. How to...
10
3010
by: Charlie | last post by:
I tried to post this before and I apologize if I am repeating myself, but I do not see the post anywhere. But anyway, I have a file, data.c, where I define all of my global variables. I then use the extern keyword to reference those variables from a header file, data.h, which I include in every file. I am defining an enum type and...
66
3653
by: karthikbalaguru | last post by:
Hi, Will 'free' return the memory Immediately to the OS ? Thx in advans, Karthik Balaguru
0
7605
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...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7665
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...
0
7962
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...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
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...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
933
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...

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.