IDL get variable size in bytes

There are two ways to get the actual size (byte) of the IDL variables.


    1.  Use built-in size function

FUNCTION sizeof, DataItem


;
; First get the information regarding the item
;
Info = SIZE (DataItem)


;
;  deduce type and number of elements
;
Type = Info(Info(0)+1)
Nitems = Info(Info(0)+2)
Size = 0


;
;  calculate number of bytes depending on item type
;
CASE Type OF


   1:  Size = 1 * Nitems


   2:  Size = 2 * Nitems


   3:  Size = 4 * Nitems


   4:  Size = 4 * Nitems


   5:  Size = 8 * Nitems


   6:  Size = 8 * Nitems


   7:  Size = 1 * Nitems


   8:  BEGIN
          Tags = TAG_NAMES (DataItem)
          Info1 = SIZE (Tags)
          FOR j = 0, Info1(Info1(0)+2)-1 DO BEGIN
             String = "Size = Size + sizeof(DataItem." + Tags(j) + ")"
             ret = EXECUTE (String)
          ENDFOR
       END


ENDCASE


;
;  return size in bytes
;
RETURN, LONG(Size)


END




    2. Use the structure information

structure = {variable:variable}

help, structure

The prompt will print out the actual number of bytes that variable occupys.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值