Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Importance of Private/ Importance of type...

Posted on 2004-09-02
7
Medium Priority
?
239 Views
Last Modified: 2010-05-02
hello experts, this is maybe a juvenile type of question, but here goes...

i'm wondering what the effect of using Private versus Public function has on the compiled EXE... does using Private make the program smaller, or use less memory?  or does using Public when not needed somehow increase the possibilty of the program being hacked... somehow using the program to gain access to something they shouldn't be allowed?

also along the same lines... i'm wondering if declaring your variables as a specific type will effect the efficiency of the program... does declaring everything as varient type use more memory?  does declaring a variable as Long when it could have been Integer use more memory once my EXE is compiled?
0
Comment
Question by:RobK6364
7 Comments
 
LVL 10

Assisted Solution

by:kiranghag
kiranghag earned 100 total points
ID: 11969740
>>does declaring a variable as Long when it could have been Integer
>>use more memory once my EXE is compiled?
yes..
but this will be noticeable only when you use huge number of variables...or larger arrays
long variables require double the space than an integer.
0
 
LVL 101

Assisted Solution

by:mlmcc
mlmcc earned 100 total points
ID: 11970146
>>does using Private make the program smaller, or use less memory?  
I don't think so.  Public and Private have to do with the visibility of the function from other forms or modules.

>>using Public when not needed somehow increase the possibilty of the program being hacked
I don't think so.  Public is really only used by the compiler.  It might if you  provided your program in a library that someone could link in to their program and try to use it but they would still need to know function names and the like.

mlmcc
0
 
LVL 7

Assisted Solution

by:_agj_
_agj_ earned 100 total points
ID: 11970683
variant types DO use up a lot of memory....use them ONLY when specifically required.

the same goes for long etc.

As for Private/Public...it only affects visibility in code, not the exe efficiency or size.
It might affect it if u are compiling to p-code. But if u compile to native assembly, there is no reason u shud have any difference.

Regarding hack-ability, declaring something as public only makes it callable...which makes it less secure/exposed to the outside world. In that sense, expose as public only your required functions. Everything that is supposd to be 'internal' and 'non-exposed' should be private.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:martin_watts
ID: 11970938
>>>>does declaring a variable as Long when it could have been Integer
>>>>use more memory once my EXE is compiled?
>>yes..
on the other hand, performance wise, using long integers (32 bits wide, "LONG" in VB) is more efficient than using short integers (16 bits wide, "INTEGER" in VB). This is because almost all processors these days are 32 bit, and internally have to convert a 16 bit integer to a 32 bit integer before processing it. Difference in VB is marginal however.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 200 total points
ID: 11971027
The reason for having both Private and Public is for the benefit of the programmer. It would be possible to have all your variables (and procedures) declared as Public, but you could easily lose track of what is modifying the value of public variables. So, as a rule of thumb, keep the scope of variables a small as possible, if necessary passing them into procedures as parameters. This does use more resources, but the effect on performance would only be marginal.

I take the same attitude to declaring the type of variables. You can save a bit of time by not declaring them, but if do you declare your variables as their intended type, then you will know sooner when you have made an error. I always have Option Explicit in the Decalarations section of the code. You can ensure that it's put there automatically: Tools/Options..., Editor tab, Require Variable Declaration checkbox.
0
 
LVL 1

Author Comment

by:RobK6364
ID: 11993229
thanks for all the replies... most of my program is "optimized" with the correct declarations..but going back finding and changing things that already work but could be "optimized" would be a pain... so basically i just wanted to get a feel for if that was a very important thing to do...

and although there seem to be some varying opinions, it seems to not be any huge concern as long as my entire program isn't all variant, which it's not.

not sure who to give the points to... so i'll split em up
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 11993573
Glad I could help

mlmcc
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question