Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2005-01

ReAllocMem problem (?)

9 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marcel Martin

Hello,

The following function SysReAllocMem comes from the file /rtl/inc/heap.inc (FPC 1.9.7 / Win32)

function SysReAllocMem(var p: pointer; size: ptrint):pointer;
[...]
   { Resize block }
   if not SysTryResizeMem(p,size) then
   begin
     minsize := MemoryManager.MemSize(p);
     if size < minsize then
       minsize := size;
     p2 := MemoryManager.AllocMem(size);
     if p2nil then
       Move(p^,p2^,minsize);
     MemoryManager.FreeMem(p);
     p := p2;
   end;
[...]

Maybe you have good reasons to write it like you did but is the instruction "MemoryManager.FreeMem(p);" intentionally always executed?
I thought that, in case it cannot increase the size of the memory allocated to p^, the memory manager would set p to nil but not that it would free it.

Suppose OneClass has a field FP which points to an array of pointers. In case of problem when attempting to increase the size of FP^, FP is freed and OneClass can no more destroy the pointed objects it created.

Up to now, I believed the code was something like

  if p2nil then
  begin
    Move(p^,p2^,minsize);
    MemoryManager.FreeMem(p);
  end;
  p := p2; <- p might be set to nil but it is not freed

and, in OneClass, one could do

  Q := FP;
  ReAllocMem(FP, NewSize (greater than current size));
  if FP = nil then
  begin
    FP := Q;
    Signal the 'Out of Memory' problem
  end;

Was your programming intentional? And if so, why?
Thanks.

Reply by email

Marcel Martin
to Marcel Martin
Marcel Martin wrote 55 lines
Hello, The following function SysReAllocMem comes from the file /rtl/inc/heap.inc (FPC 1.9.7 / Win32) function SysReAllocMem(var p: pointer; size: ptrint):pointer; [...] { Resize block } if not SysTryResizeMem(p,size) then begin minsize := MemoryManager.MemSize(p); if size < minsize then minsize := size; p2 := MemoryManager.AllocMem(size); if p2nil then Move(p^,p2^,minsize); MemoryManager.FreeMem(p); p := p2; end; [...] Maybe you have good reasons to write it like you did but is the instruction "MemoryManager.FreeMem(p);" intentionally always executed? I thought that, in case it cannot increase the size of the memory allocated to p^, the memory manager would set p to nil but not that it would free it. Suppose OneClass has a field FP which points to an array of pointers. In case of problem when attempting to increase the size of FP^, FP is freed and OneClass can no more destroy the pointed objects it created. Up to now, I believed the code was something like if p2nil then begin Move(p^,p2^,minsize); MemoryManager.FreeMem(p); end; p := p2; <- p might be set to nil but it is not freed and, in OneClass, one could do Q := FP; ReAllocMem(FP, NewSize (greater than current size)); if FP = nil then begin FP := Q; Signal the 'Out of Memory' problem end; Was your programming intentional? And if so, why? Thanks.

Considering the numerous answers I received, I am going to ask the questions otherwise: Is it a bug or not? Should I wait for a fixed version or should I manage to use it as it is because it will stay as it is? :-)
Thanks.

There is an other thing I didn't notice yesterday when I sent my post. SysReAllocMem makes use of MemoryManager.AllocMem instead of MemoryManager.GetMem, i.e., SysReAllocMem fills up with 0s the new allocated memory (whereas the ReAllocMem doc says "only the used memory is initialized, extra memory will not be zeroed out").

Reply by email

Christophe Fantoni
to Marcel Martin

Hello,

I would like to interface my SoundBlaster's SPDIF input and output in FreePascal under DOS only, but I don't find any Pascal sources to help me. For the moment, I have found one source for analog input and output but nothing for digital input or output. Have you an idea ? (maybe a technical documentation with many explications) In fact, I can build easily an hardware A/D converter for the output, but the signal in input must be captured only in digital (for Dolby Digital or DTS stream)

Many thanks for your answer,

Christophe Fantoni
French Technical Writer

Reply by email

Marco van de Voort
to Christophe Fantoni
I would like to interface my SoundBlaster's SPDIF input and output in FreePascal under DOS only, but I don't find any Pascal sources to help me.

Are there non Pascal sources that can? Most modern soundcard's APIs are not open, and only can be accessed via the vendors drivers.

Reply by email

Christophe Fantoni
to Marco van de Voort

Hello again,

I have found many pascal sources to interface the Sound Blaster compatible drivers, but only for the analog output/input. Nothing for the SPDIF or optical input/output. With sound card like SB Live! or SB Audigy, the DOS driver to interface DOS program exist... like the SPDIF input/output. But no program to use it (maybe DOS is too old, and programmers don't support this new feature in their old program)
For me, the problem is to found the technicals informations explain how to include the digital output structure in the analog ouput sources coded in Pascal. For example, the SoundLib 2 library in
http://www.crossfire-designs.de/index.php?lang=en&what=sourcecode&name=sl2.h tm , compatible vith FPC, Delphi and BP7, car easilly input and output sound stream but only in an analog way. No informations in the pascal code souce to structure and activate the digital input/output... Under Windows, this problem doesn't exist. Normal, the analog and digital input/out is managed by the Windows driver, and maybe by DirectX. But under DOS, the problem is not the same.

Many thanks for this first reponse,

Christophe Fantoni
French Technical writer

Earlier message 21 lines
----- Original Message ----- From: "Marco van de Voort" To: "Christophe Fantoni" ; "FPC-Pascal users discussions" Sent: Friday, January 28, 2005 2:28 PM Subject: Re: [fpc-pascal] SPDIF > > I would like to interface my SoundBlaster's SPDIF input and output in > > FreePascal under DOS only, but I don't find any Pascal sources to help me. > > Are there non Pascal sources that can? Most modern soundcard's APIs are not > open, and only can be accessed via the vendors drivers. > > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal >

Reply by email

Jonas Maebe
to Christophe Fantoni
Christophe Fantoni wrote 6 lines
Under Windows, this problem doesn't exist. Normal, the analog and digital input/out is managed by the Windows driver, and maybe by DirectX. But under DOS, the problem is not the same.

Indeed, therefore the question: do you know of any source code at all (i.e., possibly in a language other than Pascal) which supports output via SPDIF under Dos? It's quite possible that there is simply no documentation on how to do this, so that nobody can write any Dos code for this (unless they first reverse-engineer the Windows drivers to figure out what has to be done).

Jonas

Reply by email

Marc Santhoff
to Christophe Fantoni: I have found many pascal sources to interface the Sound Blaster compatible drivers, but…
Show quoted text 18 lines
Hello again, I have found many pascal sources to interface the Sound Blaster compatible drivers, but only for the analog output/input. Nothing for the SPDIF or optical input/output. With sound card like SB Live! or SB Audigy, the DOS driver to interface DOS program exist... like the SPDIF input/output. But no program to use it (maybe DOS is too old, and programmers don't support this new feature in their old program) For me, the problem is to found the technicals informations explain how to include the digital output structure in the analog ouput sources coded in Pascal. For example, the SoundLib 2 library in http://www.crossfire-designs.de/index.php?lang=en&what=sourcecode&name=sl2.h tm , compatible vith FPC, Delphi and BP7, car easilly input and output sound stream but only in an analog way. No informations in the pascal code souce to structure and activate the digital input/output... Under Windows, this problem doesn't exist. Normal, the analog and digital input/out is managed by the Windows driver, and maybe by DirectX. But under DOS, the problem is not the same.

I think (and would like to know, too) using a digital output makes no difference on the software side. The only matter is to switch to the right output.

If you look at it, you're writing out bytes to the analog output. This output is some form of D/A-converter for analog signals and nothing but a driver for digital signals.

So, if you use the right enconding for sending your sound data stream (this may require some software) and switched the soundcard to the SPDIF out then anything should work.

HTH,
Marc

Reply by email

Christophe Fantoni
to Marc Santhoff

Hello Mark,

In fact, my project is an hardware decoder, based on PC architecture for the moment (with motherboard and power fanless). I have created my own audio format with lossless compression (3:1) and I would like to build an hardware decoder to connect him between my DVD player and my amplifier. I use the CD Audio structure, like CD-AC3 or CD-DTS, but with my own format in each track and not with the PCM structure. I can only use digital input and output to detect and decode my own audio stream, or maybe to detect and bypass audio stream like MPEG-2 multichannel, AC3 or DTS. I can build easilly hardware A/D converter or D/A converter. Maybe, if I mix my two channels in the right channel, "format" my stream in SPDIF structure, and installing an hardware A/D converter after the analog right output, do you you think I can virtually transform the analog right output in pseudo-SPDIF output ?

Many thanks,

Christophe Fantoni
French Technical Writer

Earlier message 60 lines
----- Original Message ----- From: "Marc Santhoff" To: "FPC-Pascal users discussions" Sent: Friday, January 28, 2005 4:23 PM Subject: Re: [fpc-pascal] SPDIF > Am Fr, den 28.01.2005 schrieb Christophe Fantoni um 15:13: > > Hello again, > > > > I have found many pascal sources to interface the Sound Blaster compatible > > drivers, but only for the analog output/input. Nothing for the SPDIF or > > optical input/output. With sound card like SB Live! or SB Audigy, the DOS > > driver to interface DOS program exist... like the SPDIF input/output. But no > > program to use it (maybe DOS is too old, and programmers don't support this > > new feature in their old program) > > For me, the problem is to found the technicals informations explain how to > > include the digital output structure in the analog ouput sources coded in > > Pascal. For example, the SoundLib 2 library in > > http://www.crossfire-designs.de/index.php?lang=en&what=sourcecode&name=sl2.h > > tm , compatible vith FPC, Delphi and BP7, car easilly input and output sound > > stream but only in an analog way. No informations in the pascal code souce > > to structure and activate the digital input/output... Under Windows, this > > problem doesn't exist. Normal, the analog and digital input/out is managed > > by the Windows driver, and maybe by DirectX. But under DOS, the problem is > > not the same. > > I think (and would like to know, too) using a digital output makes no > difference on the software side. The only matter is to switch to the > right output. > > If you look at it, you're writing out bytes to the analog output. This > output is some form of D/A-converter for analog signals and nothing but > a driver for digital signals. > > So, if you use the right enconding for sending your sound data stream > (this may require some software) and switched the soundcard to the SPDIF > out then anything should work. > > HTH, > Marc > > > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal >

Reply by email

Marc Santhoff
to Christophe Fantoni
Show quoted text 14 lines
Hello Mark, In fact, my project is an hardware decoder, based on PC architecture for the moment (with motherboard and power fanless). I have created my own audio format with lossless compression (3:1) and I would like to build an hardware decoder to connect him between my DVD player and my amplifier. I use the CD Audio structure, like CD-AC3 or CD-DTS, but with my own format in each track and not with the PCM structure. I can only use digital input and output to detect and decode my own audio stream, or maybe to detect and bypass audio stream like MPEG-2 multichannel, AC3 or DTS. I can build easilly hardware A/D converter or D/A converter. Maybe, if I mix my two channels in the right channel, "format" my stream in SPDIF structure, and installing an hardware A/D converter after the analog right output, do you you think I can virtually transform the analog right output in pseudo-SPDIF output ?

I'm using a soldering iron somtimes, but I'm not that deep into making sound chips work.

Best would be to dig into some Linux source or the like to get the idea how this stuff is working.

Good luck,
Marc

Reply by email