Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Amount of memory used

  1. #1
    Member
    Join Date
    Jan 2018
    Location
    France
    Age
    69
    Posts
    50
    Rep Power
    10

    Amount of memory used

    Hi,

    Two questions :

    First=
    After writing test programs, tested them in thinair, then bundled them, I would like to know the memory impact
    of the .exe generated both code size and data size.
    I can get such info with tools like sysinternals process explorer.
    But I also wish to use data size inside the program.

    Second=
    In a previous life, I used Unix computers (From Digital Equipments, Decstations running Ultrix32) and I was
    relatively fluent with C coding and usig syscall from manpages chapter2 and fuctions from chapter 3.
    Can I find in thinbasic help or forums or ...... a guide bringing a parallel between C-unix-like functions and ThinBasic functions

    . . . . . . . . . . . . . . . . . . Unix C . . . . . . . . . . . . . . . . . . . . . . . Thin basic
    exmpl : . . . . . . . . . . handle=fopen(string,"rw",.... -->> . . . . . . . . . . . . . . . ?
    . . . . . . . . . . . . . . . strcpy(str1,str2) . . . . . . . . . . . . . . . -->> . . . . . . . . . . . . . . . this is a bad example str2=str1
    But I sure you understand my wish


    Thanks for help.

    Dany

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,103
    Blog Entries
    5
    Rep Power
    729
    Hi Dany,

    as for files, have a look at the File_* functions in the help file. There is File_Open for your fopen like uses.

    For strcpy alternative, there are many options.
    I would suggest to look at Heap_* and Memory_* functions.

    To copy string, you can actually assign it the way you did.
    Have a look at varPtr and strPtr and what it does with the assignment.

    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    Member
    Join Date
    Jan 2018
    Location
    France
    Age
    69
    Posts
    50
    Rep Power
    10
    Hi Petr,

    Thanks for answering.

    As I mentioned the copy string was a bad example, it's so easy in *basic*.

    My question was more general, since I have a collection of programs/utilities I wrote during
    my professional activity, Most writtent in K&R C, and some others in C-shell, Bourne-shell.....

    And a parallel view between Unix / ThinBasic would greatly simplify my adaptations.
    I apologize : I AM LAZY

    For program / data size, I guess I have some long time to spend, looking for this info.

    Regards,

    Dany

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,103
    Blog Entries
    5
    Rep Power
    729
    Hi Dany,

    thanks for the explanation

    If you want to make the best out of thinBASIC - please do not start with attempt to do 1:1 translation from C.

    Did you know, you can load whole file with single line of code, for example?:
    String content = Load_File("c:\myFile.txt")
    
    ThinBASIC is a different kind of beast. You can dive very low level, if you need.

    ...but you can also enjoy high level goodies, which will make your code much more maintainable/readable than C.
    For example thinBasic UDT (user defined types, like struct), which can have custom functions allowing neat object design.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5
    Member
    Join Date
    Jan 2018
    Location
    France
    Age
    69
    Posts
    50
    Rep Power
    10
    Quote Originally Posted by Petr Schreiber View Post
    Hi Dany,

    thanks for the explanation

    If you want to make the best out of thinBASIC - please do not start with attempt to do 1:1 translation from C.

    Did you know, you can load whole file with single line of code, for example?:
    String content = Load_File("c:\myFile.txt")
    
    ThinBASIC is a different kind of beast. You can dive very low level, if you need.

    ...but you can also enjoy high level goodies, which will make your code much more maintainable/readable than C.
    For example thinBasic UDT (user defined types, like struct), which can have custom functions allowing neat object design.


    Petr
    Hi Petr,

    I agree, the goal is NOT to translate 1 for 1.

    But I guess such a parallel would permit to emphasise how ThinBasic could simplify programs.
    The list may state that a C function named 'any_work(3)' may be replaced by ThinBasic function name "another_way_to_get_the_same_result() "
    As I say in previous post: "I am lazy" and if such a list exists, it would speed searches.

    An example : the program I am working on, gathers data in files in a shared directory and reports results in a console.
    But currently I'm looking how to print results in a way like old basics do with the semicolon terminator (no auto end of line).

    for x= 1 to x
    (gather data)
    (format data in a word)
    print x ; word$ ;
    next x

    The way could be : building a string word by word with "&" operator, and then prinltl(constructed_string).
    BUT I need that each word appears when detected, not when 20 words are gathered.

    Another, point :
    In C, the function main() is called from shell with commend line arguments

    main(argc,*argv)

    When I was looking in directory SampleScripts I saw someting like, but now, I do not remember which sample,
    and the directory contains 198 directories and 796 files.


    You say dive to low lever good new : I am diver CMAS:***

    Regards

    Dany

  6. #6
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,103
    Blog Entries
    5
    Rep Power
    729
    Hi Dany,

    these cases are simple ones

    Print does print to console without line break, PrintL does the same + line break.

    As for the command line parameters - please have a look at OS_Command* and OS_GetCommand* range of functions in the help file.


    I hope it helps,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  7. #7
    Member
    Join Date
    Jan 2018
    Location
    France
    Age
    69
    Posts
    50
    Rep Power
    10
    Thanks Petr,


    Printl / print : It was so bright , my eyes were dazzled .

    Os_commands : ok


    Dany

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    55
    Posts
    8,661
    Blog Entries
    2
    Rep Power
    10
    Ciao Dany,

    making a C to Basic (thinBasic) translation or parallel is quite a huge work if one want to do it professionally and honestly I do not have the time.
    Instead ... maybe we can help more if you ask about the tasks you want to achieve so we can help/suggest something on how to achieve that tasks using thinBasic

    Regarding Files, thinBasic has a specific module called "File" that you can load using:
    Uses "File"
    
    at the beginning of your code and you will have some file/directory specific functions in your script arsenal: http://www.thinbasic.com/public/prod...ileequates.htm
    Than check inside \thinBasic\SampleScripts\File\ directory and you should find some examples on how to start.

    On memory, I come from old 640KB DOS era when looking at how much memory your program was consuming was a must do task.
    In 32bit process (like thinBasic scripts) you have 2GB virtual memory for each process so you do not have to worry about memory unless you really need to load quite big piece of data to be handled at the same time.
    In any case if you want to see how to get memory info of current process, you can use the following script. It uses 2 Windows API functions GetProcessMemoryInfo and GetCurrentProcess.

    Ciao
    Eros

    Uses "Console"
     
    '---References---------------------------------------
    ' https://msdn.microsoft.com/en-us/library/windows/desktop/ms683219(v=vs.85).aspx
    ' https://msdn.microsoft.com/en-us/library/windows/desktop/ms683179(v=vs.85).aspx
    
    
      TYPE PROCESS_MEMORY_COUNTERS DWORD
       cb                         AS DWORD
       PageFaultCount             AS DWORD
       PeakWorkingSetSize         AS DWORD
       WorkingSetSize             AS DWORD
       QuotaPeakPagedPoolUsage    AS DWORD
       QuotaPagedPoolUsage        AS DWORD
       QuotaPeakNonPagedPoolUsage AS DWORD
       QuotaNonPagedPoolUsage     AS DWORD
       PagefileUsage              AS DWORD
       PeakPagefileUsage          AS DWORD
      END TYPE
    
    
      Declare Function GetProcessMemoryInfo Lib "PsApi.dll"     Alias "GetProcessMemoryInfo" (BYVAL hProcess AS DWORD, ppsmemCounters AS PROCESS_MEMORY_COUNTERS, BYVAL cb AS DWORD) AS LONG
      Declare Function GetCurrentProcess    Lib "Kernel32.dll"  Alias "GetCurrentProcess" () as Long
    '-------------------------------------------------------
     
    '---Get memory usage of current process
    FUNCTION MemoryInfo(s) AS STRING
      LOCAL sStat     AS PROCESS_MEMORY_COUNTERS
      local sBuffer   as String
    
    
      GetProcessMemoryInfo (GetCurrentProcess, sStat, SizeOf(sStat))
    
    
      sBuffer  = "Page fault count................." & $TAB & RSET$(FORMAT$(sStat.PageFaultCount, "0,"),             15) & $CRLF
      sBuffer += "Peak working set size............" & $TAB & RSET$(FORMAT$(sStat.PeakWorkingSetSize, "0,"),         15) & $CRLF
      sBuffer += "Current working set size........." & $TAB & RSET$(FORMAT$(sStat.WorkingSetSize, "0,"),             15) & $CRLF
      sBuffer += "Quota peak paged pool Usage......" & $TAB & RSET$(FORMAT$(sStat.QuotaPeakPagedPoolUsage, "0,"),    15) & $CRLF
      sBuffer += "Quota paged pool usage..........." & $TAB & RSET$(FORMAT$(sStat.QuotaPagedPoolUsage, "0,"),        15) & $CRLF
      sBuffer += "Quota peak non paged pool usage.." & $TAB & RSET$(FORMAT$(sStat.QuotaPeakNonPagedPoolUsage, "0,"), 15) & $CRLF
      sBuffer += "Quota non paged pool usage......." & $TAB & RSET$(FORMAT$(sStat.QuotaNonPagedPoolUsage, "0,"),     15) & $CRLF
      sBuffer += "Peak page fileUsage.............." & $TAB & RSET$(FORMAT$(sStat.PeakPageFileUsage, "0,"),          15) & $CRLF
      sBuffer += "Page file usage.................." & $TAB & RSET$(FORMAT$(sStat.PageFileUsage, "0,"),              15) & $CRLF
     
      function = sBuffer
      
    END FUNCTION
     
    FUNCTION TBMain () AS LONG
      dim WasteMem as String
    
    
      '---Loop while user press ESC key
      Do
        Cls
        '---Allocate some random memory from 1M to 10M
        WasteMem = string$(rnd(1000000, 10000000), $nul)
    
    
        '---Call function that get memory usage and print data
        printl MemoryInfo()
    
    
        printl "Press any key to show again memory usare or ESC to exit" in %CCOLOR_FINTENSEWHITE
    
    
      loop while WaitKey <> "[ESC]"
    
    
    END FUNCTION
    
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  9. #9
    Member
    Join Date
    Jan 2018
    Location
    France
    Age
    69
    Posts
    50
    Rep Power
    10
    Quote Originally Posted by ErosOlmi View Post
    Ciao Dany,

    making a C to Basic (thinBasic) translation or parallel is quite a huge work if one want to do it professionally and honestly I do not have the time.
    Instead ... maybe we can help more if you ask about the tasks you want to achieve so we can help/suggest something on how to achieve that tasks using thinBasic
    As I said to Petr in a previous reply, my goal is NOT to translate old C progs to ThinBasic. But after a 30 years use of Unix/C, I have some automatisms, which I should, of course, correct.
    So when I have to read data from a file I think :
    handle = fopen(filename;"R");
    While ( count = fread(handle) etc etc etc....


    instead of FileLoad(...)


    But now, I spend time with a window opened with ThinAir, and another with ThinBasic help, testing examples from templates.
    And learning, learning, learning...... Physicians says that for the health of the brain, one have to make it works. Someones spend time with sudoku or crosswords,
    I prefer building electronic circuits, old microprocessors programming. The current ThinBasic project I work on now, is a cross-assembler for RCA COSMAC processor designed in
    the 'seventies (Eros was less than 10 years old. )

    You say
    we can help/suggest something on how to achieve that tasks using thinBasic
    I'll do so... Perhaps you will feeel bored by my dumb questions sometimes.

    Regards,

    Dany

  10. #10
    Member
    Join Date
    Jan 2018
    Location
    France
    Age
    69
    Posts
    50
    Rep Power
    10
    Quote Originally Posted by ErosOlmi View Post
    Ciao Dany,

    On memory, I come from old 640KB DOS era when looking at how much memory your program was consuming was a must do task.
    In 32bit process (like thinBasic scripts) you have 2GB virtual memory for each process so you do not have to worry about memory unless you really need to load quite big piece of data to be handled at the same time.
    In any case if you want to see how to get memory info of current process, you can use the following script. It uses 2 Windows API functions GetProcessMemoryInfo and GetCurrentProcess.

    Ciao
    Eros
    Thank for this program.

    Why I posted this question ? .
    While trying some TBasic programs my PC show me a popup saying Insufficient memory.
    And the ThinBasic console did not open. So I guessed something wrong with my tests. Now I know that it was a video conversion program I started hours before
    and iconized, going mad and forking sub-processes consuming more and more memory. I killed it, and things returned OK

    As I said before, I am old..... My first job in IT departement, in 1985, was system manager of minicomputers VAX-750 from Digital Equipments.
    With 4 (four) megabytes of ram, two disks of 200 (two hundred) megabytes, a 1600 bpi tape drive for backups.
    They were running Ultrix32 OS, a unix derived from Berkeley 4.2. The loaded kernel was less than 1 megabyte
    And they were more than 20 users connected simultaneously. So, the consumed memory was a permanent worry.
    And now, I continue looking at these parameters.



    Regards,

    Dany

Page 1 of 2 12 LastLast

Similar Threads

  1. Memory information
    By Petr Schreiber in forum Win API interface
    Replies: 11
    Last Post: 09-11-2020, 13:53
  2. array and memory...
    By Oscar Ugolini in forum thinBasic General
    Replies: 2
    Last Post: 20-09-2012, 09:34
  3. Copying memory in C
    By danbaron in forum Science
    Replies: 10
    Last Post: 07-06-2011, 09:53
  4. File Save To Memory?
    By catventure in forum File
    Replies: 7
    Last Post: 31-01-2010, 20:54
  5. thinAir cache (or 'memory')?
    By Intio in forum thinAir General
    Replies: 8
    Last Post: 21-02-2009, 02:34

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •