Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Max length for PChar

Posted on 2002-06-06
10
1,312 Views
Last Modified: 2006-11-17
Is there a maximum number of characters that can be passwes to a PChar in the following function. I get crashes in Windows NT when it is very long.


function IsPatternWild(pattern: PChar): Boolean;
    begin
      Result := StrScan(pattern,'*') <> nil;
      if not Result then Result := StrScan(pattern,'?') <> nil;
    end;
0
Comment
Question by:moonrise
10 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 7059864
What is very long?
Normally PChar C functions have no problems with very long strings.
0
 

Author Comment

by:moonrise
ID: 7059878
4096 characters
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7059893
not true
max length of any allocated memory space is 2 GB !!!
so max length PChar can be 2 GB in size :)
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:moonrise
ID: 7059907
4096 characters was my answer to what I considered a long string (the length that seems to cause problems in my application but only under Win NT)
0
 
LVL 12

Accepted Solution

by:
Lee_Nover earned 100 total points
ID: 7059997
what version of winnt ?
I have win2k and It works just fine

test code:

procedure TForm1.Button1Click(Sender: TObject);
var pp: PChar;
    dwStart, bufSize: Cardinal;
begin
     bufSize:=4096 * 4096; // 16 megs !!!
     GetMem(pp, bufSize);
     try
        FillChar(pp^, bufSize-1, Ord('x'));
        PChar(pp + bufSize-2)^:='*';
        dwStart:=GetTickCount;
        Caption:=Format('%d - %d', [(Integer(IsPatternWild(pp))), GetTickCount - dwStart]);
     finally
        FreeMem(pp);
     end;
end;
0
 

Author Comment

by:moonrise
ID: 7060012
Actually I don't use the getmem and freemem, could that be the problem - but how come it still works most of the time?

Does it make a difference that it is declared as an argument of a function:

function IsPatternWild(pattern: PChar): Boolean;
   begin
     Result := StrScan(pattern,'*') <> nil;
     if not Result then Result := StrScan(pattern,'?') <> nil;
   end;
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7060087
how do you allocate your PChar ?
or where do you get it from
that's most probably the reason for your 'hangs'
0
 
LVL 6

Expert Comment

by:swift99
ID: 7061256
I have run into problems when mixing different families of getmemory and freememory methods.

For example, we had some code that used StrAlloc and FreeMem, and it failed intermittently under D3 but immediately raised exceptions under D6.
0
 
LVL 1

Expert Comment

by:pede
ID: 7066761
Maybe your string isnt always 0-terminated?

You can allocate with a standard Delphi string (eg. SetString or just assign, Str := ...). You can still pass it to your function since just by typecasting. Delphi strings are always 0-terminated.
0
 

Author Comment

by:moonrise
ID: 7066810
It turns out my problem was not with the PChar but rather with adding values into a ComboBox that were too long.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best Firemonkey component pack 1 119
drawing animated level bar based on numbers 3 104
Find and Replace Stream with 0s 8 69
How to Get Images From Server using App Tethering 11 39
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question