J3/04-120 Date: 10 Dec. 2003 To: J3 From: Dan Nagle Subject: STORAGE_SIZE Intrinsic During the final editing phase of f03, a request was made to add a STORAGE_SIZE intrinsic applicable to any type, including derived types. However, it was too late to do so at the time the request was made. This paper suggests a STORAGE_SIZE intrinsic for the next standard. A programmer may already estimate sizes in bits, but the method used is ugly ( size( transfer( ... )) ), and this method is not guaranteed to work. Number: Title: STORAGE_SIZE Intrinsic Submitted By: J3 Status: For Consideration References: Sections 13.8.2.1, 13.8.2.3, 13.8.2.7 Basic Functionality: STORAGE_SIZE would return the size in bits required to store an object of any type Rationale: Storage size in bits is a low level concept which ordinarily I would prefer to leave unspecified in standard Fortran. However, there are programmers who need to write extremely portable programs that depend on the exact sizes of data items. F03 already specifies that a programmer has access to the sizes of the standard-specified storage units. This proposal extends the programmer's access to size information to the case of derived types and intrinsic types not required to be supported (a seconmd integer kind or a third real kind, for example). Following the arguments made for the storage size constants in ISO_FORTRAN_ENV, the size is specified in bits to enable detection of unusual hardware or of unusual software conventions. STORAGE_SIZE results should be available during compilation to enable array extents to be declared, etc. STORAGE_SIZE should reside in ISO_FORTRAN_ENV because that's where the constants are, and it seems to be an environment-oriented inquiry. Estimated Impact: This is one more intrinsic to be supported, but the compiler knows the sizes of data items. Detailed Specification: Add a new intrinsic procedure STORAGE_SIZE to ISO_FORTRAN_ENV. STORAGE_SIZE ( arg ) arg is a scalar of any type and kind. If arg is declared as a CLASS variable, the result is computed based on the dynamic type. arg need not be allocated, but a pointer of CLASS must have a target (so there's something whose size may be returned). Result is a default integer whose value is the size in bits of arg. It is the size of an array of args of size N+1 minus the size of an array of size N (that is, storage_size includes any padding). Example: integer( selected_int_kind( 1) ) :: small_int ! estimate file size on this processor count_fsu = storage_size( small_int) / file_storage_size & * size( very_large_array) Note: A derived type may have a component array so large that the default integer cannot hold its size in bits. This point may argue in favor of STORAGE_SIZE returning the largest inetger available. However, even this is no guarantee that this will work in all cases. (It's end cases like this one that prevented STORAGE_SIZE from being added last time!) On the other hand, if the largest integer a processor has cannot hold the storage size of an object, it is likely that the program has exceeded some other limit as well. History: