Memory error with FiveWin + xHarbour.com

Post Reply
Patrizio
Posts: 90
Joined: Wed Nov 07, 2007 8:56 am
Location: Italy
Contact:

Memory error with FiveWin + xHarbour.com

Post by Patrizio »

Ola Antonio,

This code generate a memory error when the memory allocated is close to 140 mega if I compile it with FWH + xHarbour.com

If i compile the same code with FWH + xHarbour.org the error is generated when the memory allocated is close to 2 giga (size of the ram available in the pc).

If i compile the code with xHarbour.com without FWH the error is generated at 2 giga too.

Code: Select all

#include "Fivewin.ch"
#include "HBClass.ch"

PROC Main()
   LOCAL aObj  := Array(1000000)
   LOCAL  n := 0
   LOCAL oDlg, oGet, oButton
   DEFINE DIALOG oDlg
   @ 1,  1 GET       oGet        VAR n             SIZE 80, 10
   @ 2,  1 BUTTON    oButton     PROMPT "Start"    SIZE 80,  8 ACTION Button1_Click(@aObj,oGet)
   ACTIVATE DIALOG oDlg CENTER
   aSize(aObj,0)
RETURN

FUNC Button1_Click(aObj,oGet)
   LOCAL nTot  := Len(aObj)
   LOCAL n     := 0
   FOR n := 1 TO nTot
      aObj[n]  := OggettoProva():Init()
      oGet:SetText("Object in memory: " + lTrim(Str(n)))
      SysRefresh()
   NEXT
RETURN

CLASS OggettoProva
   DATA _Array1                        AS ARRAY       INIT aFill(Array(12),1)
   DATA _Array2                        AS ARRAY       INIT aFill(Array(12),1)
   DATA _Array3                        AS ARRAY       INIT aFill(Array(12),1)
   DATA _Array4                        AS ARRAY       INIT aFill(Array(12),1)
   DATA _Array5                        AS ARRAY       INIT aFill(Array(12),1)
   DATA _Array6                        AS ARRAY       INIT aFill(Array(12),1)
   DATA _Array7                        AS ARRAY       INIT aFill(Array(12),1)
   DATA _Array8                        AS ARRAY       INIT aFill(Array(12),1)
   DATA _Array9                        AS ARRAY       INIT aFill(Array(12),1)
   DATA _Array10                       AS ARRAY       INIT aFill(Array(12),1)
   CONSTRUCTOR Init
   METHOD      End
   DESTRUCTOR  Destroy
ENDCLASS

METHOD Init() CLASS OggettoProva
RETURN Self

METHOD End()  CLASS OggettoProva
   ::_Array1  := NIL
   ::_Array2  := NIL
   ::_Array3  := NIL
   ::_Array4  := NIL
   ::_Array5  := NIL
   ::_Array6  := NIL
   ::_Array7  := NIL
   ::_Array8  := NIL
   ::_Array9  := NIL
   ::_Array10 := NIL
RETURN NIL

PROCEDURE Destroy CLASS OggettoProva
   ::End()
RETURN NIL
 
This is only a stress test written to understand the problem with my program.

I use FWH 9.04 and xHarbour.com May 2009

Any idea?
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Memory error with FiveWin + xHarbour.com

Post by Antonio Linares »

Patrizio,

Please add this line and test it again:

Code: Select all

FUNC Button1_Click(aObj,oGet)
   LOCAL nTot  := Len(aObj)
   LOCAL n     := 0
   FOR n := 1 TO nTot
      aObj[n]  := OggettoProva():Init()
      oGet:SetText("Object in memory: " + lTrim(Str(n)))
      SysRefresh()
      hb_gcAll()  // this one! calls to the garbage collector
   NEXT
RETURN
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
Patrizio
Posts: 90
Joined: Wed Nov 07, 2007 8:56 am
Location: Italy
Contact:

Re: Memory error with FiveWin + xHarbour.com

Post by Patrizio »

Antonio, error again :(
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Memory error with FiveWin + xHarbour.com

Post by Antonio Linares »

Patrizio,

In my opinion it is not related with FWH at all, but with the used C compiler. FWH is not related at all with the arrays management that you are basing your tests on, neither on the classes management. All these is managed by Harbour/xHarbour themselves.

C compilers use malloc() and free() memory management functions instensively, and their code are not the same from one C compiler to another.

In my opinion, Borland C and Microsoft C compilers are far superior than Pelles C (used in xhb commercial). Borland and Microsoft C compilers have been very much tested to build many tools, including an operating system like Windows, many Borland tools, etc.

If your code is the same and the Borland version is managing the memory much better, then it is a clear proof about what I say.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Patrizio
Posts: 90
Joined: Wed Nov 07, 2007 8:56 am
Location: Italy
Contact:

Re: Memory error with FiveWin + xHarbour.com

Post by Patrizio »

Antonio, I agree with you, but I don't understand why the source compiled with only xHarbour.com (with pelles c compiler) it's ok and the source compiled with xHarbour.com (the same pelles c compiler) and FiveWin it's ko.

Code: Select all

#include "HBClass.ch"

PROC Main()
   LOCAL aObj  := Array(1000000)
   LOCAL  n := 0
   Button1_Click(@aObj)
   aSize(aObj,0)
RETURN

FUNC Button1_Click(aObj)
   LOCAL nTot  := Len(aObj)
   LOCAL n     := 0
   CLS
   FOR n := 1 TO nTot
      aObj[n]  := OggettoProva():Init()
      @ 0, 0 SAY "Object in memory: " + lTrim(Str(n))
   NEXT
RETURN
 
With the same object struct of the first sample

However today I'll try to compile with xHarbour.com and another c compiler.
Patrizio
Posts: 90
Joined: Wed Nov 07, 2007 8:56 am
Location: Italy
Contact:

Re: Memory error with FiveWin + xHarbour.com

Post by Patrizio »

Antonio, I tried to compile with another c compiler and xHarbour.com but I had a lot of problems.

Trying to get a solution for my trouble, I found this note in xharbour.com documentation:
You can NOT use any C Compiler other than xCC if you use xHarbour.com’s xHarbour Builder. If you want to use another C Compiler you also need to have the xHarbour binaries and libraries compiled for your chosen C Compiler.
So, what I have to do? :)

Does someone have a sample of prg compiled with xHarbour.com and another c compiler (BCC or MSVC) or updated version of Pelles C (6.00) ?
User avatar
fafi
Posts: 169
Joined: Mon Feb 25, 2008 2:42 am

Re: Memory error with FiveWin + xHarbour.com

Post by fafi »

User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Memory error with FiveWin + xHarbour.com

Post by Antonio Linares »

Patrizio,

You should be able to use Microsoft C with xHarbour commercial. It is the one we use here for xHarbour commercial users :-)

Regarding the difference between console mode and FWH mode, keep in mind that a simple sentence like @ ..., ... SAY ... builds a complete Windows control in FWH, and in console mode just paints a text. So the FWH version will always consume more memory.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Patrizio
Posts: 90
Joined: Wed Nov 07, 2007 8:56 am
Location: Italy
Contact:

Re: Memory error with FiveWin + xHarbour.com

Post by Patrizio »

Thansk Antonio e Fafi, i'll try in this way.
Regarding the difference between console mode and FWH mode, keep in mind that a simple sentence like @ ..., ... SAY ... builds a complete Windows control in FWH, and in console mode just paints a text. So the FWH version will always consume more memory.
Antonio, the problem isn't the different memory usage between console mode and fwh mode, the problem is the limit of memory (2giga vs 140 mega).

In console mode with xHarbour.com there isn't that limit, neither in FWH mode with xHarbour.org. Why there is this limit in FWH mode with xHarbour.com?
Patrizio
Posts: 90
Joined: Wed Nov 07, 2007 8:56 am
Location: Italy
Contact:

Re: Memory error with FiveWin + xHarbour.com

Post by Patrizio »

Antonio Linares wrote:You should be able to use Microsoft C with xHarbour commercial. It is the one we use here for xHarbour commercial users :-)
Antonio, what version of Microsoft C do you use? I try with VC9 and have some errors in linking.

Fafi, do you know the difference between the xHarbour commercial version and free.xharbour.com ?
Patrizio
Posts: 90
Joined: Wed Nov 07, 2007 8:56 am
Location: Italy
Contact:

Re: Memory error with FiveWin + xHarbour.com

Post by Patrizio »

Antonio

With xHarbour-v1.21.6658-for-BorlandC_v5.5.exe download from free.xharbour.com and BCC55 and FiveWin the program it's ok, crash at 2 giga.

With xHarbour-v1.21.6658-for-Microsoft_VisualC_v9.exe and VC9 and FiveWin the program it's ok, crash at 2 giga.

VC9 doesn't have LIBC.LIB, I use a old lib of VC7 and i have some problems with oleVariantToItem, not exported by xharbour.

:)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Memory error with FiveWin + xHarbour.com

Post by Antonio Linares »

Patricio,

Do you mean VC98 ?

Please copy here the link error, thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
Patrizio
Posts: 90
Joined: Wed Nov 07, 2007 8:56 am
Location: Italy
Contact:

Re: Memory error with FiveWin + xHarbour.com

Post by Patrizio »

No Antonio, VC9: Microsoft Visual C++ 2008 Express Edition.

Errors i'm getting:
LINK : fatal error LNK1104: impossibile aprire il file 'LIBC.lib'
I read on msdn that this library is the single-thread version and VC9 use only LIBCMT.LIB. I'm getting the LIBC.lib from an older version of Visual C++.
FiveHCM.lib(ACTX.obj) : error LNK2019: riferimento al simbolo esterno _hb_oleVariantToItem non risolto nella funzione _InvokeEvent
This error with xHarbour commercial was fixed with xHB.obj (found on this forum), but if I include xHB.obj I have this errors:
xhb.obj : error LNK2019: riferimento al simbolo esterno "void * __cdecl hb_xgrab(unsigned long)" (?hb_xgrab@@YAPAXK@Z) non risolto nella funzione "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
xhb.obj : error LNK2019: riferimento al simbolo esterno "void __cdecl hb_xfree(void *)" (?hb_xfree@@YAXPAX@Z) non risolto nella funzione "void __cdecl operator delete(void *)" (??3@YAXPAX@Z)
So, i tried to remove the xHB.obj and include a modified version of Win32Ole.prg with the self-made correction and finally I have compiled.

This with xHarbour downloaded from free.xharbour.com but this is not xHarbour commercial. If I try to compile with xHarbour commercial I still have problems. I'm going to make other tests and I'll post results.
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Memory error with FiveWin + xHarbour.com

Post by Antonio Linares »

Patrizio,

You can use this flag to avoid the requirement for LIBC:

Code: Select all

link ... /nologo /subsystem:windows /force:multiple /NODEFAULTLIB:libc
 
Please review FWH\samples\buildhm.bat

Also, try to use this xhb2.obj instead of xhb.obj:
http://www.fivetechsoft.com/files/xhb2.obj
regards, saludos

Antonio Linares
www.fivetechsoft.com
Patrizio
Posts: 90
Joined: Wed Nov 07, 2007 8:56 am
Location: Italy
Contact:

Re: Memory error with FiveWin + xHarbour.com

Post by Patrizio »

Antonio, I found the problem :D

The linker command line generated by xBuilderW for a console application is different by the command line generated for a GUI application with FiveWin.

Code: Select all

xlink.exe <omissis> MyPrg.obj "xhb.lib"  ... <omissis>

Code: Select all

xlink.exe <omissis> MyPrg.obj "FiveHCM.lib" "FiveHMX.lib" "[b]OptG.lib[/b]" "xhb.lib"  ... <omissis>
I've analyzed the difference between the two map file (thanks EMG) and I saw many different calls to the same function like _hb_xalloc, _hb_xgrab, _hb_xrealloc, _hb_xfree (etc), these functions are both in OptG.lib and xHB.lib.

I've tried to remove the OptG.lib from the xlink command line and the limit growth to 2 giga.

So, anybody knows what is this lib used for? I suppose that I'd ask this in the xHarbour.com newsgroup.
Post Reply