[C] Maximaal 65.535 LocalLocks?

Pagina: 1
Acties:
  • 40 views sinds 30-01-2008

  • Gonadan
  • Registratie: Februari 2004
  • Laatst online: 08:43

Gonadan

Admin Beeld & Geluid, Harde Waren
Topicstarter
Mijn programma crasht na 65535 aanroepen van LocalLock.
Beter gezegd: na 65535 aanroepen van LocalLock geeft hij 0 terug.
En crasht mijn programma dus als ik de resultaten van die functie wil gebruiken.

De code na verwijdering van onzinnige weggecommentariëerde meuk :+

C:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
typedef char* LPSTR;

_declspec(dllexport) HANDLE WINAPI _GetInfo();

int main(int args, char *argv[])
{
    int n;
    for (n=0;n<65540;n++)
    {
        readinfo();
        printf("%d\n", n+1);
    }

    return 0;
}


readinfo()
{
    LPSTR lpBuf;
    lpBuf = NULL;

    lpBuf = LocalLock(_GetInfo());

    printf("%d - ", lpBuf);

    LocalUnlock(lpBuf);
    LocalFree(lpBuf);

    return NULL;
}


Het laatste stukje van de console:
code:
1
2
3
4
5
6
7
8
9
10
2326704 - 65531
2326704 - 65532
2326704 - 65533
2326704 - 65534
2326704 - 65535
0 - 65536
0 - 65537
0 - 65538
0 - 65539
0 - 65540

Voor de duidelijkheid:
dat eerste getal is het adres dat de LocalLock teruggaf.
het tweede getal is het iteratienummer.

De aangeroepen functie geeft een pointer naar een struct terug.
Dit ter informatie al denk ik dat het er niets mee te maken heeft want zonder LocalLock kan ik de functie wel vaker aanroepen alleen kan ik dan de resultaten niet uitlezen :+

Heeft iemand enig idee? :)

Look for the signal in your life, not the noise.

Canon R6 | RF 24-70 f/2.8 L | 50 f/1.8 STM | 430EX II
Sigma 85 f/1.4 Art | 100-400 Contemporary
Zeiss Distagon 21 f/2.8


  • mulder
  • Registratie: Augustus 2001
  • Laatst online: 23-02 19:58

mulder

ik spuug op het trottoir

zou heel goed de max van je datatype kunnen zijn

oogjes open, snaveltjes dicht


  • Gonadan
  • Registratie: Februari 2004
  • Laatst online: 08:43

Gonadan

Admin Beeld & Geluid, Harde Waren
Topicstarter
Don Facundo schreef op woensdag 29 maart 2006 @ 12:03:
zou heel goed de max van je datatype kunnen zijn
Daar dacht ik ook aan, want een char is 8 bit bijvoorbeeld.

Alleen heb ik wat lopen testen en dat lijkt niet uit te maken.
Misschien verander ik het verkeerde type hoor ;)
Ja, dat doe ik denk ik :P

Look for the signal in your life, not the noise.

Canon R6 | RF 24-70 f/2.8 L | 50 f/1.8 STM | 430EX II
Sigma 85 f/1.4 Art | 100-400 Contemporary
Zeiss Distagon 21 f/2.8


  • igmar
  • Registratie: April 2000
  • Laatst online: 23-02 20:52

igmar

ISO20022

Ja. Ten eerste : Dit heeft echt totaal niks met C te maken, het probleem is specifiek voor Win32. Verder, als je op LocalLock had gezocht, had je gezien dat de area met LocalAlloc() gealloceerd moet worden. De remarks van die functie :

If the heap does not contain sufficient free space to satisfy the request,
LocalAlloc returns NULL.

The GlobalAlloc and LocalAlloc functions are limited to a combined total
of 65,536 handles for GMEM_MOVEABLE and LMEM_MOVEABLE
memory per process. This limitation does not apply to GMEM_FIXED
or LMEM_FIXED memory. 


en dat komt overeen met het gedrag zoals je nu ziet. Weet je wel zeker dat LocalUnlock() en LocalFree() goed gaan ?

edit:

LocalLock() returned niks, maar je gebruikt wel de returnwaarde. Je moet dus de waarde van LocalAlloc() aan LocalUnlock() / LocalFree() als param doorgeven.

[ Voor 14% gewijzigd door igmar op 29-03-2006 12:14 ]


  • Gonadan
  • Registratie: Februari 2004
  • Laatst online: 08:43

Gonadan

Admin Beeld & Geluid, Harde Waren
Topicstarter
igmar schreef op woensdag 29 maart 2006 @ 12:08:
[...]


Ja. Ten eerste : Dit heeft echt totaal niks met C te maken, het probleem is specifiek voor Win32. Verder, als je op LocalLock had gezocht, had je gezien dat de area met LocalAlloc() gealloceerd moet worden. De remarks van die functie :
Ik had wél gezocht :P

LocalAlloc() gebruik ik nooit :S
Hij werkt evengoed, maar ja ik kijk wel.
If the heap does not contain sufficient free space to satisfy the request,
LocalAlloc returns NULL.

The GlobalAlloc and LocalAlloc functions are limited to a combined total
of 65,536 handles for GMEM_MOVEABLE and LMEM_MOVEABLE
memory per process. This limitation does not apply to GMEM_FIXED
or LMEM_FIXED memory. 
Aaah, dank je wel, die had ik niet gevonden.
en dat komt overeen met het gedrag zoals je nu ziet. Weet je wel zeker dat LocalUnlock() en LocalFree() goed gaan ?

edit:

LocalLock() returned niks, maar je gebruikt wel de returnwaarde. Je moet dus de waarde van LocalAlloc() aan LocalUnlock() / LocalFree() als param doorgeven.
Huh, LocalLock() returned wel degelijk iets.
Maar nu ben ik dus in de war :?

Look for the signal in your life, not the noise.

Canon R6 | RF 24-70 f/2.8 L | 50 f/1.8 STM | 430EX II
Sigma 85 f/1.4 Art | 100-400 Contemporary
Zeiss Distagon 21 f/2.8


  • Woy
  • Registratie: April 2000
  • Niet online

Woy

Moderator Devschuur®
LocalFree wil graag een Handle naar je memory block.

LocalLock returnt een pointer naar de eerste byte van het gelockte geheugen. Het lijkt mij dus dat je LocalFree en LocalUnlock niet goed gaat. Denk dat je de Handle van _GetInfo() moet gebruiken om LocalFree() en LocalUnlock() aan te roepen.

[ Voor 7% gewijzigd door Woy op 29-03-2006 12:39 ]

“Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.”


  • Gonadan
  • Registratie: Februari 2004
  • Laatst online: 08:43

Gonadan

Admin Beeld & Geluid, Harde Waren
Topicstarter
rwb schreef op woensdag 29 maart 2006 @ 12:35:
LocalFree wil graag een Handle naar je memory block.

LocalLock returnt een pointer naar de eerste byte van het gelockte geheugen. Het lijkt mij dus dat je LocalFree niet goed gaat. Denk dat je de Handle van _GetInfo() moet gebruiken om LocalFree() en LocalUnlock() aan te roepen.
Dus je bedoelt dat ik eerst de handle in een var stop.
En dan die var ga locken, en dat dus in een andere var stop.

Maar dan zou ik dus die 2e var moeten unlocken en die 1e var moeten freeën?

Ach wat zwets ik toch, ik ga het gewoon proberen :+

Look for the signal in your life, not the noise.

Canon R6 | RF 24-70 f/2.8 L | 50 f/1.8 STM | 430EX II
Sigma 85 f/1.4 Art | 100-400 Contemporary
Zeiss Distagon 21 f/2.8


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 22:12

.oisyn

Moderator Devschuur®

Demotivational Speaker

Ja sorry hoor maar het staat toch echt duidelijk in de documentatie

LocalLock, verwacht een HLOCAL als parameter, en returnt een LPVOID (oftewel een void*)
LocalUnlock, verwacht ook een HLOCAL, en dus NIET de LPVOID die je terugkreeg van LocalLock
LocalFree, zelfde verhaal.

Dus ik sluit je topic. 't Is gewoon een kwestie van goed lezen.

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.

Pagina: 1

Dit topic is gesloten.