Показать сообщение отдельно

VirtualAlloc
  #1  
Старый 21.03.2009, 18:48
NorB
Познающий
Регистрация: 20.07.2007
Сообщений: 99
С нами: 9900206

Репутация: 25
По умолчанию VirtualAlloc

Есть структура моя их на страницу виртуальной памяти 128 штук умещается код какбы рабочий но одно но когда в функции add условие идет на 2 ветку, где при заполнении страници нужно выделить новую страницу, она невыделяется посмотрите что нетак. Там скорее всего lpPtr+=dwPageSize; вроде все как мсдн даже написал а первый параметр в вирт аллок выходит что неправельный%( я непому почему что нетак...
Код:
#include <windows.h>
#include <stdio.h>              // for printf
#include <stdlib.h>             // for exit
#include <conio.h>
#include <string.h>
#include <iostream.h>
#define PAGELIMIT 80            // ask for this many pages

LPTSTR lpNxtPage;               // address of the next page to ask for
DWORD dwPages = 1;              // count of pages gotten so far
DWORD count=0;
DWORD count2=0;
DWORD dwPageSize;
LPVOID lpvBase;
DWORD lpPtr;

struct list {
  char dt[20];
  int x;
  int y;
  int v;
  };
  
list * arr;

void add(int val1, int val2,int val3, char *val4){
     if(((count2+1)%128)!=0){
     strcpy(arr[count].dt, val4);
     arr[count].x= val1;
     arr[count].y= val2;
     arr[count].v= val3;
     count++;
     count2++;
     printf ("On saime page # %d.\n", dwPages);
                        }else{
                         lpPtr+=dwPageSize;
                         arr=(list*)VirtualAlloc((LPVOID)lpPtr,dwPageSize,MEM_COMMIT,PAGE_READWRITE);
                         
                         if (arr == NULL ){
                         printf("VirtualAlloc failed\n");
                         } else {
                         printf ("Allocating another page.\n");
                         };

                         
                         strcpy(arr[count].dt, val4);
                         arr[count].x= val1;
                         arr[count].y= val2;
                         arr[count].v= val3;
                         dwPages++;
                         count++;
                         count2=0;
                         printf ("On new page ¹ %d.\n", dwPages);
                         }
     };


int main(int argc, char *argv[])
{
  SYSTEM_INFO sSysInfo;
  GetSystemInfo(&sSysInfo);     // initialize the structure
  printf ("This computer has page size %d.\n", sSysInfo.dwPageSize);
  printf ("size of struct  %d.\n", sizeof(list));
  dwPageSize = sSysInfo.dwPageSize;
  
  arr=(list*)VirtualAlloc(NULL,PAGELIMIT*dwPageSize,MEM_RESERVE,PAGE_READWRITE);
  arr=(list*)VirtualAlloc(NULL,dwPageSize,MEM_COMMIT,PAGE_READWRITE);

  lpPtr=(DWORD)arr;
  printf("vvedite znachenie, stroku, stolbec, tip\n");
  int a,b,c;
  char tipp[20];
  cin>>a>>b>>c>>tipp;
  for (int f=0; f<130; f++){
  add(a,b,c,tipp);
};
  cout<<arr[130].x<<arr[130].y<<arr[130].v<<arr[130].dt;
  
  system("PAUSE");	
  return 0;
}
 
Ответить с цитированием