2015-01-13 3 views
-2

이미지 그리드를 화면에 표시하는 프로젝트에서 작업 중입니다. 그런 다음 각 타일에 개별적으로 액세스 할 수 있어야하므로 각 타일의 개별 정보를 나타 내기 위해 다음 클래스를 만들어야한다는 것을 알았습니다. 나는 그런 cTile tiles[5]이 클래스의 배열을 delare 할 때클래스의 배열이 많은 메모리에 그립니다.

class cTile 
{ 
    //a class representing position in the graphics api im using (irrlicht) 
    position2d<s32> Position; 
    int imgIndex_x; 
    int imgIndex_y; 
    int offset; 
    // a class representing a square in the graphics api im using (irrlicht) 
    rect<s32> TextureSq; 
    // initialized at a negative number because zero is a valid number represent the global id number of tile ie its texture  
    int Gid = -1;              

public: 
    cTile(); 
    ~cTile(); 

    bool isSolid; 
    void animate(); 
    void setGid(int gid); 
    int getGid(); 
    void setSolid(bool state); 
    void draw(IVideoDriver* vdr, ITexture * sourceImage); 
}; 

내가 얻을 :

Error 1 error C2148: total size of array must not exceed 0x7fffffff bytes

+2

무엇이'sizeof (cTile)'입니까? – Robert

+0

@ 로버트 그래, 내 추측은 ~ 40 이상일 수 없다고 생각합니다. 그래서 뭔가 다른 것입니다. – IdeaHat

+0

@IdeaHat 어쩌면'position2d' 또는'rect'에 문제가있을 수 있습니다. 그래서 크기를 알고 싶습니다 ^^ – Robert

답변

0

컴파일러 및 운영 체제는 일반적으로 작은을위한 공간보다 지역 변수 메모리 공간의 크기를 설정 동적 메모리.

하나의 쉬운 해결책은 std::vector을 사용하는 것입니다.

다른 해결책은 operator new을 사용하여 "힙에"배열을 할당하는 것입니다.

+0

을 테스트하기 위해 만든'int main()'내부에서 선언했는데, 원래의 컨텍스트가'new' 키를 사용했음을 알리기 위해서입니다. 단어를'tiles = new ctiles [max]'로 바꾸고 sam 오류가 발생했습니다. 그러나 벡터를 사용하면 잘 작동합니다. – Dcoollx

관련 문제