Subject | Re: [firebird-support] UDF:s and strings i Delphi |
---|---|
Author | Kjell Rilbe |
Post date | 2005-02-10T19:48:52Z |
Thanks Pavel for your elaborate answer. I think it was spot on. :-)
A couple of followup questions though. If I let FB allocate memory the
way you said, does the max length specified in the DECLARE control how
much memory FB allocates?
So, if I do this:
0 terminator into the OutStr buffer?
In that case, it would be tempting to declare with the maximum size
which I think I read is 32767:
-----
DECLARE EXTERNAL FUNCTION myudffunc
CSTRING(10), CSTRING(32767)
RETURNS PARAMETER 2
ENTRY_POINT 'myUDF' MODULE_NAME 'myudfmodule';
-----
But I assume this would impact performance since it has to allocate a
lot more memory on each call. Right? Would this impact be big? I mean,
the buffer would be released as soon as the value is returned to the
client in a dataset or written into a field, woudln't it? So it wouldn't
really waste more than one such buffer at a time. (Per concurrent query
that uses that UDF, that is.)
Thanks,
Kjell
--
--------------------------------------
Kjell Rilbe
Adressmarknaden AM AB
E-post: kjell.rilbe@...
Telefon: 08-761 06 55
Mobil: 0733-44 24 64
A couple of followup questions though. If I let FB allocate memory the
way you said, does the max length specified in the DECLARE control how
much memory FB allocates?
So, if I do this:
> -----Will myUDF cause buffer overruns if it writes more than 10 characters +
> procedure myUDF(InStr: PChar; var OutStr: PChar); cdecl; export;
> begin
> // check if OutStr<>nil - then FB has allocated the memory
> // processing
> ...
> end;
> -----
> DECLARE EXTERNAL FUNCTION myudffunc
> CSTRING(10), CSTRING(10)
> RETURNS PARAMETER 2
> ENTRY_POINT 'myUDF' MODULE_NAME 'myudfmodule';
> -----
0 terminator into the OutStr buffer?
In that case, it would be tempting to declare with the maximum size
which I think I read is 32767:
-----
DECLARE EXTERNAL FUNCTION myudffunc
CSTRING(10), CSTRING(32767)
RETURNS PARAMETER 2
ENTRY_POINT 'myUDF' MODULE_NAME 'myudfmodule';
-----
But I assume this would impact performance since it has to allocate a
lot more memory on each call. Right? Would this impact be big? I mean,
the buffer would be released as soon as the value is returned to the
client in a dataset or written into a field, woudln't it? So it wouldn't
really waste more than one such buffer at a time. (Per concurrent query
that uses that UDF, that is.)
Thanks,
Kjell
--
--------------------------------------
Kjell Rilbe
Adressmarknaden AM AB
E-post: kjell.rilbe@...
Telefon: 08-761 06 55
Mobil: 0733-44 24 64