====================================================================== Microsoft(R) Product Support Services Application Note (Text File) BV0699: MEMORY MANAGEMENT QUESTIONS & ANSWERS ====================================================================== Revision Date: 11/92 No Disk Included The following information applies to Microsoft Visual Basic(TM) for Windows(TM) versions 1.0 and 2.0. -------------------------------------------------------------------- | INFORMATION PROVIDED IN THIS DOCUMENT AND ANY SOFTWARE THAT MAY | | ACCOMPANY THIS DOCUMENT (collectively referred to as an | | Application Note) IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY | | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO | | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A | | PARTICULAR PURPOSE. The user assumes the entire risk as to the | | accuracy and the use of this Application Note. This Application | | Note may be copied and distributed subject to the following | | conditions: 1) All text must be copied without modification and | | all pages must be included; 2) If software is included, all files | | on the disk(s) must be copied without modification [the MS-DOS(R) | | utility DISKCOPY is appropriate for this purpose]; 3) All | | components of this Application Note must be distributed together; | | and 4) This Application Note may not be distributed for profit. | | | | Copyright 1992 Microsoft Corporation. All Rights Reserved. | | Microsoft and MS-DOS are registered trademarks and QuickBasic, | | Visual Basic, and Windows are trademarks of Microsoft Corporation. | -------------------------------------------------------------------- 1. Q. What should I do when I receive the error message "Out of memory" at design time or at run time? A. The "Out of memory" error message does not necessarily indicate that you have run out of conventional memory. This error message occurs most commonly when you have exhausted the system resources. To determine if a lack of system resources has caused this problem, check the percentage of free system resources in the About Program Manager dialog box. (To view this dialog box, choose About Program Manager from the Help menu in Program Manager.) If the percentage of system resources available is less than 10 percent, you have probably exhausted the system resources. Because each loaded form and control consumes system resources, you can conserve system resources by limiting the number of forms and controls that you load. Using the Load statement, load only the forms that are necessary. When a form is no longer needed, unload it with the Unload statement to free system resources associated with that form. Simply hiding the form with the Hide method does not free system resources. If you are using Microsoft Visual Basic version 2.0 for Windows, you can conserve system resources by using the graphical controls, such as the image, shape, and line controls. The label control is also a graphical control in version 2.0. Because these controls paint themselves directly onto the form, they use significantly fewer system resources than nongraphical controls. For example, it is recommended that you use an image control in place of a picture control wherever possible. For more information on how to optimize resource usage, please refer to Chapter 11 of the version 2.0 "Programmer's Guide." The "Out of memory" error message can also occur if you have run out of memory in a particular 64-kilobyte (64K) code or data segment. Appendix D of the Visual Basic 2.0 "Programmer's Guide" outlines various memory limits related to code and data segments. Because Visual Basic 2.0 supports arrays greater than 64K up to the limit of total available memory, it is possible to run out of total memory. The amount of total memory available is reported in the About Program Manager dialog box. 2. Q. What is the maximum string size in Microsoft Visual Basic for Windows? A. Visual Basic allows strings up to 64K. This is different from Microsoft QuickBasic(TM) and the Microsoft Basic Professional Development System, which allow strings up to 32K only. For more information on code and data limits, please refer to Appendix D of the Visual Basic version 2.0 "Programmer's Guide." 3. Q. I am using version 1.0 of Microsoft Visual Basic for Windows. When I try to dimension an array larger than 64K, I receive the error message "Subscript out of range." What is causing this problem? A. Version 1.0 of Visual Basic does not contain built-in support for huge arrays (that is, arrays larger than 64K). Therefore, if you try to dimension an array larger than 64K, you receive the "Subscript out of range" error message. The maximum array size for any array type is 64K; however, each form and/or module can declare as many 64K arrays as there is memory available to handle. This 64K array limit no longer exists in version 2.0 of Visual Basic, which supports huge arrays of any type. 4. Q. When I try to declare an array within a user-defined type in version 1.0 of Microsoft Visual Basic for Windows, I receive the error message "feature unavailable." What is causing this error? A. Visual Basic version 1.0 does not support arrays within user- defined types. To get support for arrays within user-defined types, you must use Visual Basic version 2.0. 5. Q. Where can I find more information about Microsoft Visual Basic for Windows data types? A. Information on Visual Basic data types can be found in Chapter 7 of the Visual Basic version 2.0 "Programmer's Guide" and on pages 83 and 84 of Chapter 9 in the Visual Basic version 1.0 "Programmer's Guide." Please note that the default type for Visual Basic 2.0 is Variant and several Visual Basic functions now return the Variant data type instead of a numeric data type, such as Single or Double. In version 1.0, the default data type is Single. This change may impact your existing code written using Visual Basic version 1.0. For example, if you are printing the return value of the SerialDate function, the result will be a formatted date string instead of a serial number. To change the default type, you must include a Def statement in the general declaration section of each form and module. For example, if you want to set the default type to Single, which is the default type for version 1.0, use the statement DefSNG and specify the letter range A through Z in all forms and modules for the project.