Carl Jacobs wrote:
> Can I run two processes within a single application - the implication
> being that two copies of the memory manager would be invoked - or
> does the second process have to be a seperate application?

You can run your program twice. This is no different from running
Notepad twice to have two documents open, or from running Delphi twice
to debug your design-time component code. The two processes are
completely separate; the only thing they have in common is their
underlying file name.

> s := Format('%d',[var]); <-- Sometimes crash on this sort of line,
> with s being the problem!

Turn on the "debug DCUs" compiler option so you can see what line it's
really crashing on.

> I have multiple threads running which are performing lots of string
> manipulation - with those strings being passed around between the
> different threads. The strings/cells as defined and used in the code
> example above does not normally bear any relationship to the strings
> being passed around by the threads - except of course that the same
> memory manager is being used to allocate and free those strings.

Those threads -- are you using descendants of TThread, or are you using
the threading API directly? If the latter, are you using the
CreateThread API function? If you are, then you must be sure to set the
IsMultithreaded global variable to True. That's something that TThread
and the BeginThread function do for you, but that the API cannot do.
IsMultithreaded tells the memory manager whether to serialize requests
with a critical section.

> What is more suspicious is that I can run my program (a simulator of
> sorts) at different speeds (normal speed, x2, x3 up to x10) and the
> problem will only show up at the higher speeds - hence a greater
> probability of overlapping memory management.

That means you probably have a race condition. The faster you run the
race, the faster two runners will bump into each other.

Do you have any global (unit-level) string variables? How about other
string variables that can be accessed by multiple threads? This includes
string properties of a TThread object that the main thread would set or
read. You need to protect access to such variables with a critical
section (or a mutex, or whatever).

> Does this explanation of my problem even make sense?
> 
> I look forward to any help that can be given.

You could give each thread its own memory manager. An easy way to do
that is to use the heap API functions. Each thread could be given its
own heap, and all allocations and deallocations would be from the
thread's private heap. That won't work if you share strings between
threads, though, since one thread would be unable to free any other
thread's strings.

-- 
Rob


-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED] 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/delphi-en/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to