Linux下std::ifstream成员函数对应系统调用验证

2023-11-04

最近在分析离线数据使用时的bug,发现代码中对std::ifstream成员函数使用存在疑问,所以就写了个简单测试程序来分析std::ifstream成员函数对应那些系统调用。

目录

1.gcount

2.seekg和tellg

3.read


代码如下:

test.cpp

#include <iostream>
#include <fstream>
#include <atomic>
#include <string>

using namespace std;

/*
1.fseek函数:C语言标准库函数
作用:设置文件读写位置
函数原型:int fseek(FILE *fp, LONG offset, int origin);
参数含义:
    fp 文件指针 
    offset 相对于origin规定的偏移位置量 
    origin 指针移动的起始位置,取值如下: 
        SEEK_SET 文件开始位置 
        SEEK_CUR 文件当前位置 
        SEEK_END 文件结束位置
返回值:
    成功,返回0,失败返回非0值,并设置error的值,可以用perror()函数输出错误。

2.ftell函数:C语言标准库函数
作用:用于得到文件位置指针当前位置相对于文件首的偏移字节数
原型:
#include <stdio.h>
long ftell(FILE *stream);
获取文件大小:首先将文件的当前位置移到文件的末尾,然后调用函数ftell()获得当前位置相对于文件首的位移,该位移值等于文件所含字节数。
fseek(fp, 0L,SEEK_END); 
len = ftell(fp); 

3.lseek函数:linux下系统调用
lseek: 用于改变一个文件读写指针位置的一个系统调用。指针位置可以是绝对的或者相对的。
    和fseek函数类似,但lseek返回的是一个off_t数值
#include <sys/types.h>
#include <unistd.h>
off_t lseek(int fd, off_t offset, int whence);
offset为正则向文件末尾移动(向前移),为负数则向文件头部(向后移)。
返回值:
正确时返回文件读写指针距文件开头的字节大小,出错返回-1
lseek的作用是打开文件下一次读写的开始位置,因此还有以下两个作用
(1)拓展文件,不过一定要一次写的操作。迅雷等下载工具在下载文件时候先扩展一个空间然后再下载的。
int fd = open("test.txt",O_RDWR);
lseek(fd,0x1000, SEEK_SET);
write(fd, "a", 1);
close(fd);

(2)获取文件大小。
int fd = open("test.txt", O_RDWR);
printf("file size:%d \n", lseek(fd, 0, SEEK_END));
close(fd);

总结:lseek 功能包含 ftell + fseek

*/

/*
C++中seekp() seekg() tellp() tellg() 
seekp:设置输出文件流的文件流指针位置
tellp::获取输出文件流的文件流指针位置
seekg:设置输入文件流的文件流指针位置
tellg:获取输入文件流的文件流指针位置
函数原型:
ostream& seekp( streampos pos );
ostream& seekp( streamoff off, ios::seek_dir dir );
istream& seekg( streampos pos );
istream& seekg( streamoff off, ios::seek_dir dir );
ostream& tellp() 
istream& tellg() 
参数含义:
pos:新的文件流指针位置值
off:需要偏移的值
dir:搜索的起始位置
dir参数用于对文件流指针的定位操作上,代表搜索的起始位置
在ios中定义的枚举类型:
    enum seek_dir {beg, cur, end};
    含义如下:
        ios::beg:文件流的起始位置
        ios::cur:文件流的当前位置
        ios::end:文件流的结束位置

gcount(): 返回在对象上执行的最后一个未格式化的输入操作中提取的字符数,不涉及调用系统api
获取文件大小:
seekg(0, std::ios::end);
tellg();
*/

/*
iostream类评估流状态的4个功能函数:good(),bad(),fail(),和eof(),具体功能如下:
good():流没有遇到错误。
bad():数据流已遇到效应的流(即存储器分配失败,没有缓流等)。
fail():的完整性的错误:通常可恢复的错误(格式化/解析失败)。
eof():已达到文件结尾(EOF)字符。
*/

static std::atomic<int> count_num(0);

#define DB_IsBigEnd_FromRPHeaderAttr( HeaderAttr ) \
	((bool) (HeaderAttr & 0X00000001))

//typedef unsigned int uint_t;
using uint_t = unsigned int;
typedef unsigned char Byte;
typedef unsigned short	u_short;


#define DB_FORMAT_VER_MAX_LENGTH	(16)

#define DB_DATA_VER_MAX_LENGTH		(16)

#define DB_AUTHOR_MAX_LENGTH		(8)

#define DB_DATE_MAX_LENGTH			(8)

/* 小端到大端的变换宏 */
#define _V_GET_LITTLE_SHORT( x )	(short)( ( ( *((Byte*)x+1) ) << 8 ) | (*((Byte*)x)) )
#define _V_GET_LITTLE_LONG( x )		(int)( ( ( *((Byte*)x+3) ) << 24 ) | (( *((Byte*)x+2) ) << 16 ) \
        | (( *((Byte*)x+1) ) << 8 ) | ( *((Byte*)x) ) )
#define _V_GET_LITTLE_FLOAT( x ) (*((float *)(x)))

#define _V_GET_BIGENDDIAN_SHORT( x ) (short)( ( ( *((Byte*)x) ) << 8 ) | (*((Byte*)x+1)) )
#define _V_GET_BIGENDDIAN_LONG( x )	(int)( ( ( *((Byte*)x) ) << 24 ) | (( *((Byte*)x+1) ) << 16 ) \
    | (( *((Byte*)x+2) ) << 8 ) |  ( *((Byte*)x+3) ) )


typedef struct _DB_Header_t
{
	uint_t		unAttr;									
	uint_t		unHeaderSize;							
	uint_t		unFrameSize;							
	char		cFormatVer[DB_FORMAT_VER_MAX_LENGTH];	
	char		cDataVer[DB_DATA_VER_MAX_LENGTH];		
	char		cAuthor[DB_AUTHOR_MAX_LENGTH];		
	char		cDate[DB_DATE_MAX_LENGTH];			
	uint_t		unCalcRegionMaxSize;					
	uint_t		unInfoRegionMaxSize;					
	uint_t		unRPLinkShapePointMaxCnt;				
	uint_t		unNameMaxLength;						
	uint_t		unNameFrameOffset;						
	uint_t		unDistrictFrameOffset;					
	uint_t		unLevelCnt;								
	uint_t		unLevelRecordSize;						
	uint_t		pstLevelTable;							
} DB_Header_t ;

typedef struct _DB_Level_t
{
	u_int	unAttr;							
	u_int	unCalcRegionManagerHeaderOffset;
	u_int	unUnCompressedCalcRegionManagerHeaderOffset;
	u_int	unCalcRegionManagerHeaderSize;	
	u_int	unInfoRegionManagerHeaderOffset;
	u_int	unInfoRegionManagerHeaderSize;	
	u_int	unAdjacentNodeManagerHeaderOffset;
	u_int	unAdjacentNodeManagerHeaderSize;
} DB_Level_t;

typedef struct _DB_NameFrame_t
{
	u_int		unFrameSize;	
	u_int		unStructSize;	
	u_int		unNameIdxCnt;	
	u_int		unNameIdxSize;	
	u_int		punIdxTable;	
	u_int		pusNameTable;	
} DB_NameFrame_t;

typedef struct _DB_DistrictFrame_t
{
	u_int					unFrameSize;		
	u_int					unStructSize;		
	u_int					unDistrictCnt;		
	u_int					unDistrictSize;		
	u_int					pstDistrictTable;	
} DB_DistrictFrame_t;

typedef struct _DB_AbsoluteNodeID_t
{
	u_int 	unNodeID ;			
	u_int 	unNodeExtendID ;
} DB_AbsoluteNodeID_t;

typedef struct _DB_AbsoluteLinkID_t
{
	u_int	unLinkIDPart1;	 
	u_int 	unLinkIDPart2;	 
	u_int 	unLinkAttr;	 	 	 
} DB_AbsoluteLinkID_t;

typedef struct _DB_AdjacentNode_t
{
	u_int					nLongitude ;
	u_int					nLatitude ;
	DB_AbsoluteNodeID_t	stNodeID ;
	DB_AbsoluteLinkID_t	stLinkID ;
	bool					bIsStartNode ;
} DB_AdjacentNode_t ;

typedef struct _DB_AdjacentNodeMgr_t
{
	u_int					unSize ;
	u_int					unStructSize ;
	u_int					unCnt ;
	u_int					unRecordSize;	
	u_int					pstAdjNodes;
} DB_AdjacentNodeMgr_t ;

typedef struct _DB_CalcRegion_ManagerHeader_t
{
	u_int					unFrameSize;		
	u_int					unRankInfo;			
	u_int					unRegionCnt;		
	u_int					unRegionIdxSize;	
	u_int					pstRegionIdxTable;	
} DB_CalcRegion_ManagerHeader_t;

typedef struct _DB_DistrictRecord_t
{
	u_short		usCityNameIdx;	
	u_short		usCountyNameIdx;
} DB_DistrictRecord_t;

typedef struct _DB_CalcRegion_Idx_t
{
	u_short	unRegionOffset;					
	u_short	unUnCompressedRegionOffset ;	
	u_short	unRegionSize;					
	u_short	unCompressedRegionSize ;		
} DB_CalcRegion_Idx_t;


//多个对象指向同一个文件操作
class DBFile
{
public:
    DBFile(std::ifstream *DBFileHandle);
    ~DBFile();

	int32_t seek_cur_to_end_size(std::ifstream *m_pDBFileHandle, int32_t start_seek_pos);

	static int32_t seek_cur_to_end_size(std::ifstream& pFile, int32_t start_seek_pos);

private:
    std::ifstream *m_pDBFileHandle;
};

DBFile::DBFile(std::ifstream *DBFileHandle)
{
    if(DBFileHandle) {
        count_num++;
        m_pDBFileHandle = DBFileHandle;
    }
}

DBFile::~DBFile()
{
    if(m_pDBFileHandle) {
        count_num--;
        if(count_num <= 0) {
            count_num = 0;
        }
        if (count_num <= 0 && m_pDBFileHandle->good() && m_pDBFileHandle->is_open()) {
            m_pDBFileHandle->close();
        }
    }
}

int32_t DBFile::seek_cur_to_end_size(std::ifstream *m_pDBFileHandle, int32_t start_seek_pos)
{
	if(!m_pDBFileHandle) {
		return 0;
	}
	m_pDBFileHandle->seekg(0, std::ios::end);
	if(!m_pDBFileHandle->good()) {
		return 0;
	}
	int32_t seekg_end_size = m_pDBFileHandle->tellg();

	m_pDBFileHandle->seekg(start_seek_pos, std::ios::beg);
	if(!m_pDBFileHandle->good()) {
		return 0;
	}
	int32_t seekg_cur_size = m_pDBFileHandle->tellg();

	return seekg_end_size - seekg_cur_size;
}

int32_t DBFile::seek_cur_to_end_size(std::ifstream& pFile, int32_t start_seek_pos)
{
    std::cout << 11111 << std::endl;
	pFile.seekg(0, std::ios::end);
	if(!pFile.good()) {
		return 0;
	}
    std::cout << 22222 << std::endl;
	int32_t seekg_end_size = pFile.tellg();
    std::cout << 33333 << std::endl;
	pFile.seekg(start_seek_pos, std::ios::beg);
    std::cout << 44444 << std::endl;
	if(!pFile.good()) {
		return 0;
	}
    std::cout << 55555 << std::endl;
	int32_t seekg_cur_size = pFile.tellg();
    std::cout << 666666 << std::endl;

	return seekg_end_size - seekg_cur_size;
}

class DBParser
{
public:
	DBParser() ;
	virtual ~DBParser();
    int Init (const std::string DBPathFileName);
    int GetHeaderSize (u_int* punHeaderSize);
    int GetHeader (u_int unHeaderSize, DB_Header_t* pstHeaderInfo);
    int GetNameFrameSize (u_int* punNameFrameSize);
    int GetNameFrame (
				u_int unOffset,
				u_int unFrameSize,
				DB_NameFrame_t* pstNameFrame);
    int GetDistrictFrameSize (
                    u_int* punDistrictFrameSize);

    int GetDistrictFrame (
                    u_int unOffset,
                    u_int unFrameSize,
                    DB_DistrictFrame_t* pstDistrictFrame);

    int GetAdjacentNodeManager (
                        u_int unMgrOffset,
                        u_int unMgrSize,
                        DB_AdjacentNodeMgr_t* pstAdjNodeMgr);

    int GetCalcRegionManagerHeader( u_int unHeaderOffset,
                                    u_int unHeaderSize,
                                    DB_CalcRegion_ManagerHeader_t* pstManagerHeader);

private:
    std::ifstream		m_hDBFileHandle ;
    bool		        m_bIsBigEnd ;
    std::string         m_rp_db_file_path;
    std::atomic_bool	m_rp_db_file_install;
};

DBParser::DBParser() {
    m_rp_db_file_path = "";
    m_rp_db_file_install = false;
}

DBParser::~DBParser() {
    m_rp_db_file_install = false;
    if (m_hDBFileHandle.is_open()) {
        m_hDBFileHandle.close() ;
	}
}


int DBParser::Init (const std::string DBPathFileName)
{
    m_hDBFileHandle.open(DBPathFileName , std::ios::in|std::ios::binary);
    if (!m_hDBFileHandle.is_open()) {
        return -1;
    }
    DBFile dbFile(&m_hDBFileHandle);
    unsigned int unHeaderAttr = 0;
    m_hDBFileHandle.read((char*)&unHeaderAttr, sizeof(unHeaderAttr)) ;
    if (!m_hDBFileHandle.good()) {
        return -2;
    }
    std::cout << "gcount = " << m_hDBFileHandle.gcount() << std::endl;
    m_bIsBigEnd = DB_IsBigEnd_FromRPHeaderAttr(unHeaderAttr) ;
    unsigned int unHeaderSize = 0;
    std::cout << 99999 << std::endl;
    m_hDBFileHandle.read((char*)&unHeaderSize, sizeof(unHeaderSize));
    std::cout << 101010 << std::endl;
    if (m_hDBFileHandle.gcount() != sizeof(unHeaderSize)) {
        return -3;
    }
    std::cout << "gcount = " << m_hDBFileHandle.gcount() << std::endl;
    if (unHeaderSize > 1024 * 1024) // header size 不应该大于 1M
    {
	    return -4;
    }
	
    DB_Header_t* header = new DB_Header_t; // malloc(unHeaderSize);
    if (NULL == header) {
		return -5;
    }

    m_hDBFileHandle.seekg(0, std::ios::beg); //seek to begin

    m_hDBFileHandle.read((char*)header, unHeaderSize);

    if (m_hDBFileHandle.gcount() != unHeaderSize) {
		free(header);
        return -3;
    }

    m_hDBFileHandle.seekg(0, std::ios::end);

    ulong fileSize = m_hDBFileHandle.tellg();
    u_int frameSize = header->unFrameSize;
    free(header);
    if (frameSize != (u_int)fileSize) {
        return -6;
    }

    m_rp_db_file_path = DBPathFileName;
    m_rp_db_file_install = true;
    m_hDBFileHandle.close();

    return 0;
}

int DBParser::GetHeaderSize (u_int* punHeaderSize)
{
    if (punHeaderSize == NULL) {
        return -1;
    }
    if((true == m_rp_db_file_install) && (!m_hDBFileHandle.is_open()))
    {
        m_hDBFileHandle.open(m_rp_db_file_path , std::ios::in|std::ios::binary);
    }
    DBFile oRpFile(&m_hDBFileHandle);

    if (!m_hDBFileHandle.is_open())
	{
		*punHeaderSize = 0;
		return -2 ;
	}

    int size = DBFile::seek_cur_to_end_size(m_hDBFileHandle, 4);

    if (!m_hDBFileHandle.good()) {
        return -3;
    }
    if(size < sizeof(*punHeaderSize)){
        return -4;
    }
    std::cout << 77777 << std::endl;
    m_hDBFileHandle.read ((char*)punHeaderSize, sizeof (*punHeaderSize)) ;
    std::cout << "gcount = " << m_hDBFileHandle.gcount() << std::endl;
    std::cout << 88888 << std::endl;
    if (!m_hDBFileHandle.good()) {
        return false;
    }

	if (m_bIsBigEnd)
	{
		*punHeaderSize = _V_GET_LITTLE_LONG(punHeaderSize) ;
	}

    return 0;
}

int DBParser::GetHeader (u_int unHeaderSize,
	                    DB_Header_t* pstHeaderInfo)
{
	u_int	i = 0;
	Byte*	pbtHeaderInfo = (Byte*)pstHeaderInfo;
	DB_Level_t *pstLevelTable;

	if (unHeaderSize == 0 || pstHeaderInfo == NULL) {
        return -1;
    }

    if((true == m_rp_db_file_install) && (!m_hDBFileHandle.is_open()))
    {
        m_hDBFileHandle.open(m_rp_db_file_path , std::ios::in|std::ios::binary);
    }
    DBFile oRpFile(&m_hDBFileHandle);

    if (!m_hDBFileHandle.is_open()) {
        return -2;
    }
    m_hDBFileHandle.seekg(0, std::ios::beg);
    if (!m_hDBFileHandle.good()) {
        return -3;
    }
    /*
    char tmpBuf[9016] = {0};
    m_hDBFileHandle.read(tmpBuf, unHeaderSize);
    */
    std::cout << "begin gcount  gcount" << std::endl;
    m_hDBFileHandle.read((char*)pbtHeaderInfo, unHeaderSize);
    std::cout << "gcount = " << m_hDBFileHandle.gcount() << std::endl;
    std::cout << "begin gcount  gcount" << std::endl;
    if (!m_hDBFileHandle.good()) {
        return -3;
    } 

	if (m_bIsBigEnd)
	{
		pstHeaderInfo->unAttr = _V_GET_LITTLE_LONG (&pstHeaderInfo->unAttr) ;
		pstHeaderInfo->unHeaderSize = _V_GET_LITTLE_LONG (&pstHeaderInfo->unHeaderSize) ;
		pstHeaderInfo->unFrameSize = _V_GET_LITTLE_LONG (&pstHeaderInfo->unFrameSize) ;
		pstHeaderInfo->unCalcRegionMaxSize = _V_GET_LITTLE_LONG (&pstHeaderInfo->unCalcRegionMaxSize) ;
		pstHeaderInfo->unInfoRegionMaxSize = _V_GET_LITTLE_LONG (&pstHeaderInfo->unInfoRegionMaxSize) ;
		pstHeaderInfo->unRPLinkShapePointMaxCnt = _V_GET_LITTLE_LONG (&pstHeaderInfo->unRPLinkShapePointMaxCnt) ;
		pstHeaderInfo->unNameMaxLength = _V_GET_LITTLE_LONG (&pstHeaderInfo->unNameMaxLength) ;
		pstHeaderInfo->unNameFrameOffset = _V_GET_LITTLE_LONG (&pstHeaderInfo->unNameFrameOffset) ;
		pstHeaderInfo->unDistrictFrameOffset = _V_GET_LITTLE_LONG (&pstHeaderInfo->unDistrictFrameOffset) ;
		pstHeaderInfo->unLevelCnt = _V_GET_LITTLE_LONG (&pstHeaderInfo->unLevelCnt) ;
		pstHeaderInfo->unLevelRecordSize = _V_GET_LITTLE_LONG (&pstHeaderInfo->unLevelRecordSize) ;
		pstHeaderInfo->pstLevelTable = _V_GET_LITTLE_LONG (&pstHeaderInfo->pstLevelTable) ;
	}

	pstLevelTable = (DB_Level_t*)(pbtHeaderInfo + (u_int)(pstHeaderInfo->pstLevelTable));

    if(pstLevelTable == NULL) {
        return -4;
    }

	if (m_bIsBigEnd)
	{
		for (i = 0; i < pstHeaderInfo->unLevelCnt ; i++)
		{
			pstLevelTable->unAttr =
				_V_GET_LITTLE_LONG (&pstLevelTable->unAttr) ;
			pstLevelTable->unCalcRegionManagerHeaderOffset =
				_V_GET_LITTLE_LONG (&pstLevelTable->unCalcRegionManagerHeaderOffset) ;
			pstLevelTable->unUnCompressedCalcRegionManagerHeaderOffset =
				_V_GET_LITTLE_LONG (&pstLevelTable->unUnCompressedCalcRegionManagerHeaderOffset) ;
			pstLevelTable->unCalcRegionManagerHeaderSize =
				_V_GET_LITTLE_LONG (&pstLevelTable->unCalcRegionManagerHeaderSize) ;
			pstLevelTable->unInfoRegionManagerHeaderOffset =
				_V_GET_LITTLE_LONG (&pstLevelTable->unInfoRegionManagerHeaderOffset) ;
			pstLevelTable->unInfoRegionManagerHeaderSize =
				_V_GET_LITTLE_LONG (&pstLevelTable->unInfoRegionManagerHeaderSize) ;
			pstLevelTable->unAdjacentNodeManagerHeaderOffset =
				_V_GET_LITTLE_LONG (&pstLevelTable->unAdjacentNodeManagerHeaderOffset) ;
			pstLevelTable->unAdjacentNodeManagerHeaderSize =
				_V_GET_LITTLE_LONG (&pstLevelTable->unAdjacentNodeManagerHeaderSize) ;

			pstLevelTable = (DB_Level_t*)((Byte*)pstLevelTable + pstHeaderInfo->unLevelRecordSize );
		}
	}

	return 0;
}

int DBParser::GetNameFrameSize(u_int* punNameFrameSize)
{
    DB_Header_t stHeaderInfo ;
	DB_NameFrame_t stNameFrame ;

	if (punNameFrameSize == 0) {
        return -1;
    }
    if((true == m_rp_db_file_install) && (!m_hDBFileHandle.is_open()))
    {
        m_hDBFileHandle.open(m_rp_db_file_path , std::ios::in|std::ios::binary);
    }
    DBFile oRpFile(&m_hDBFileHandle);
    if (!m_hDBFileHandle.is_open()) {
        return -1;
    }

    m_hDBFileHandle.seekg (0, std::ios::beg);
    if (!m_hDBFileHandle.good()) {
        return -2;
    }

    m_hDBFileHandle.read((char*)&stHeaderInfo, sizeof(stHeaderInfo)) ;
    if (stHeaderInfo.unNameFrameOffset == 0) {
        return -3;
    }
	if (m_bIsBigEnd)
	{
		stHeaderInfo.unNameFrameOffset = _V_GET_LITTLE_LONG (&stHeaderInfo.unNameFrameOffset) ;
	}
    m_hDBFileHandle.seekg(stHeaderInfo.unNameFrameOffset, std::ios::beg);
    if (!m_hDBFileHandle.good()) {
        return -2;
    }

    m_hDBFileHandle.read((char*)&stNameFrame.unFrameSize, sizeof(stNameFrame.unFrameSize)) ;
    if (stNameFrame.unFrameSize == 0) {
        return -3;
    }
	*punNameFrameSize = stNameFrame.unFrameSize ;

	if (m_bIsBigEnd)
	{
		*punNameFrameSize = _V_GET_LITTLE_LONG (punNameFrameSize) ;
	}

    return 0;
}


int DBParser::GetNameFrame (u_int unOffset,
				            u_int unFrameSize,
				            DB_NameFrame_t* pstNameFrame)
{
	u_int	unTempOffset = 0;
	u_int	unWordsCnt ;
	Byte*	pbyNameFrame = (Byte*)pstNameFrame ;
	u_int	*punIdxTable;
	u_short	*pusNameTable;

	if (unOffset == 0 || unFrameSize == 0 || pstNameFrame == NULL) {
        return -1;
    }

    if((true == m_rp_db_file_install) && (!m_hDBFileHandle.is_open()))
    {
        m_hDBFileHandle.open(m_rp_db_file_path , std::ios::in|std::ios::binary);
    }
    DBFile oRpFile(&m_hDBFileHandle);
    if (!m_hDBFileHandle.is_open()) {
        return -2;
    }

    m_hDBFileHandle.seekg (unOffset, std::ios::beg);
    if (!m_hDBFileHandle.good()) {
        return -3;
    }

    m_hDBFileHandle.read ((char*)pbyNameFrame, unFrameSize) ;
    if (pstNameFrame->unFrameSize == 0 ||
		pstNameFrame->unNameIdxCnt == 0) {
            return -4;
    }
	if (m_bIsBigEnd)
	{
		pstNameFrame->unFrameSize = _V_GET_LITTLE_LONG (&pstNameFrame->unFrameSize) ;
		pstNameFrame->unStructSize = _V_GET_LITTLE_LONG (&pstNameFrame->unStructSize) ;
		pstNameFrame->unNameIdxCnt = _V_GET_LITTLE_LONG (&pstNameFrame->unNameIdxCnt) ;
		pstNameFrame->unNameIdxSize = _V_GET_LITTLE_LONG (&pstNameFrame->unNameIdxSize) ;
	}
	unTempOffset = pstNameFrame->unStructSize;

	if (unTempOffset == 0 || unTempOffset % 4 != 0
		|| unTempOffset != (u_int)pstNameFrame->punIdxTable) {
            return -4;
    }
	punIdxTable = (u_int*)(pbyNameFrame + (u_int)pstNameFrame->punIdxTable) ;
	if (m_bIsBigEnd)
	{
		for ( u_int i = 0; i < pstNameFrame->unNameIdxCnt; ++i )
		{
			*punIdxTable = _V_GET_LITTLE_LONG(punIdxTable);
			punIdxTable = (u_int*)( (Byte*)punIdxTable + pstNameFrame->unNameIdxSize );
		}
	}

	unTempOffset += sizeof(u_int) * pstNameFrame->unNameIdxCnt ;
	unWordsCnt = unFrameSize - unTempOffset ;
	if (unWordsCnt == 0 || unWordsCnt % sizeof(u_short) != 0) {
        return -4;
    }
	unWordsCnt /= sizeof(u_short) ;
	pusNameTable = (u_short*)(pbyNameFrame + (u_int)pstNameFrame->pusNameTable);
	if (m_bIsBigEnd)
	{
		for ( u_int i = 0; i < unWordsCnt; ++i )
		{
			*pusNameTable = _V_GET_LITTLE_SHORT( pusNameTable );
			++pusNameTable;
		}
	}

	return 0;
}

int DBParser::GetDistrictFrameSize (
				u_int* punDistrictFrameSize)
{
	DB_Header_t stHeaderInfo ;
	DB_DistrictFrame_t stDistrictFrame ;

	if (punDistrictFrameSize == 0) {
        return -1;
    }
    if((true == m_rp_db_file_install) && (!m_hDBFileHandle.is_open()))
    {
        m_hDBFileHandle.open(m_rp_db_file_path , std::ios::in|std::ios::binary);
    }
    DBFile oRpFile(&m_hDBFileHandle);
    if (!m_hDBFileHandle.is_open()) {
        return -4;
    }

    m_hDBFileHandle.seekg (0, std::ios::beg);
    if (!m_hDBFileHandle.good()) {
        return -4;
    }

    m_hDBFileHandle.read ((char*)&stHeaderInfo, sizeof(stHeaderInfo));
    if (stHeaderInfo.unDistrictFrameOffset == 0) {
        return -4;
    }
	if (m_bIsBigEnd)
	{
		stHeaderInfo.unDistrictFrameOffset = _V_GET_LITTLE_LONG (&stHeaderInfo.unDistrictFrameOffset) ;
	}

    m_hDBFileHandle.seekg (stHeaderInfo.unDistrictFrameOffset, std::ios::beg);
    if (!m_hDBFileHandle.good()) {
        return -4;
    }
    m_hDBFileHandle.read ((char*)&stDistrictFrame.unFrameSize, sizeof(stDistrictFrame.unFrameSize)) ;
    if (stDistrictFrame.unFrameSize == 0) {
        return -4;
    }

	*punDistrictFrameSize = stDistrictFrame.unFrameSize;
	if (m_bIsBigEnd)
	{
		*punDistrictFrameSize = _V_GET_LITTLE_LONG (punDistrictFrameSize) ;
	}

	return 0;
}

int DBParser::GetDistrictFrame (
				u_int unOffset,
				u_int unFrameSize,
				DB_DistrictFrame_t* pstDistrictFrame)
{
	DB_DistrictRecord_t *pstDistrictTable;
	Byte*	pbyDistrictFrame = (Byte*)pstDistrictFrame ;

	if (unOffset == 0 || unFrameSize == 0 || pstDistrictFrame == NULL) {
        return  -1; 
    } 
    if((true == m_rp_db_file_install) && (!m_hDBFileHandle.is_open()))
    {
        m_hDBFileHandle.open(m_rp_db_file_path , std::ios::in|std::ios::binary);
    }
    DBFile oRpFile(&m_hDBFileHandle);
    if (!m_hDBFileHandle.is_open()) {
        return  -4;
    }

    m_hDBFileHandle.seekg (unOffset, std::ios::beg);
    if (!m_hDBFileHandle.good()) {
        return  -4;
    }

    m_hDBFileHandle.read ((char*)pbyDistrictFrame, unFrameSize) ;
    if (pstDistrictFrame->unFrameSize == 0 ||
		pstDistrictFrame->unDistrictCnt == 0) {
            return  -4;
    }

	if (m_bIsBigEnd)
	{
		pstDistrictFrame->unFrameSize = _V_GET_LITTLE_LONG (&pstDistrictFrame->unFrameSize) ;
		pstDistrictFrame->unStructSize = _V_GET_LITTLE_LONG (&pstDistrictFrame->unStructSize) ;
		pstDistrictFrame->unDistrictCnt = _V_GET_LITTLE_LONG (&pstDistrictFrame->unDistrictCnt) ;
		pstDistrictFrame->unDistrictSize = _V_GET_LITTLE_LONG (&pstDistrictFrame->unDistrictSize) ;
	}
	if( pstDistrictFrame->unStructSize == 0
		|| pstDistrictFrame->unStructSize % 4 != 0
		|| pstDistrictFrame->unStructSize != (u_int)(pstDistrictFrame->pstDistrictTable)) {
        return -4;
    }
		
	pstDistrictTable = (DB_DistrictRecord_t*)
		( pbyDistrictFrame + (u_int)(pstDistrictFrame->pstDistrictTable) );
	if (m_bIsBigEnd)
	{
		for ( u_int i = 0; i < pstDistrictFrame->unDistrictCnt; ++i )
		{
			pstDistrictTable->usCityNameIdx = _V_GET_LITTLE_SHORT( &(pstDistrictTable->usCityNameIdx) );
			pstDistrictTable->usCountyNameIdx = _V_GET_LITTLE_SHORT( &(pstDistrictTable->usCountyNameIdx) );

			pstDistrictTable = (DB_DistrictRecord_t*)
				( (Byte*)pstDistrictTable + pstDistrictFrame->unDistrictSize );
		}
	}

	return 0;
}

int DBParser::GetAdjacentNodeManager (
					u_int unMgrOffset,
					u_int unMgrSize,
					DB_AdjacentNodeMgr_t* pstAdjNodeMgr)
{

	u_int	i = 0;
	Byte*	pbtAdjNodeMgr = (Byte*)pstAdjNodeMgr ;
	DB_AdjacentNode_t *pstAdjacentNode;

	if (unMgrOffset == 0 || unMgrSize == 0 ||
		pstAdjNodeMgr == NULL) {
        return  -1;
    } 
    if((true == m_rp_db_file_install) && (!m_hDBFileHandle.is_open()))
    {
        m_hDBFileHandle.open(m_rp_db_file_path , std::ios::in|std::ios::binary);
    }
    DBFile oRpFile(&m_hDBFileHandle);
    if (!m_hDBFileHandle.is_open()) {
        return  -4;
    }

    m_hDBFileHandle.seekg(unMgrOffset, std::ios::beg);
    if (!m_hDBFileHandle.good()) {
        return  -4;
    }
    m_hDBFileHandle.read ((char*)pbtAdjNodeMgr, unMgrSize) ;
    if (!m_hDBFileHandle.good()) {
        return  -4;
    }

	if (m_bIsBigEnd)
	{
		pstAdjNodeMgr->unSize = _V_GET_LITTLE_LONG (&pstAdjNodeMgr->unSize) ;
		pstAdjNodeMgr->unStructSize = _V_GET_LITTLE_LONG (&pstAdjNodeMgr->unStructSize) ;
		pstAdjNodeMgr->unCnt = _V_GET_LITTLE_LONG (&pstAdjNodeMgr->unCnt) ;
		pstAdjNodeMgr->unRecordSize = _V_GET_LITTLE_LONG (&pstAdjNodeMgr->unRecordSize) ;
		pstAdjNodeMgr->pstAdjNodes = _V_GET_LITTLE_LONG (&pstAdjNodeMgr->pstAdjNodes) ;
	}

	pstAdjacentNode = (DB_AdjacentNode_t*)( pbtAdjNodeMgr + (u_int)(pstAdjNodeMgr->pstAdjNodes) );

	if ( m_bIsBigEnd )
	{
		for ( i = 0; i < pstAdjNodeMgr->unCnt; ++i )
		{
			pstAdjacentNode->nLongitude = _V_GET_LITTLE_LONG (
				&(pstAdjacentNode->nLongitude) );
			pstAdjacentNode->nLatitude = _V_GET_LITTLE_LONG (
				&(pstAdjacentNode->nLatitude) );
			pstAdjacentNode->stNodeID.unNodeID = _V_GET_LITTLE_LONG (
				&(pstAdjacentNode->stNodeID.unNodeID) );
			pstAdjacentNode->stNodeID.unNodeExtendID = _V_GET_LITTLE_LONG (
				&(pstAdjacentNode->stNodeID.unNodeExtendID) );

			pstAdjacentNode = (DB_AdjacentNode_t*)
				( (Byte*)pstAdjacentNode + pstAdjNodeMgr->unRecordSize );
		}
	}

	return 0;
}

int DBParser::GetCalcRegionManagerHeader (
					u_int unHeaderOffset,
				    u_int unHeaderSize,
				    DB_CalcRegion_ManagerHeader_t* pstManagerHeader)
{
	u_int	i = 0;
	Byte*	pbtCalcRegionManagerHeader = (Byte*)pstManagerHeader ;
	DB_CalcRegion_Idx_t *pstRegionIdxTable;

	if (unHeaderOffset == 0 || unHeaderSize == 0 ||
		pstManagerHeader == NULL) {
        return  -1;
    }
    if((true == m_rp_db_file_install) && (!m_hDBFileHandle.is_open()))
    {
        m_hDBFileHandle.open(m_rp_db_file_path , std::ios::in|std::ios::binary);
    }
    DBFile oRpFile(&m_hDBFileHandle);
    if (!m_hDBFileHandle.is_open()) {
        return  -4;
    }

    m_hDBFileHandle.seekg (unHeaderOffset, std::ios::beg);
    if (!m_hDBFileHandle.good()) {
        return  -4;
    }
    m_hDBFileHandle.read ((char*)pbtCalcRegionManagerHeader, unHeaderSize) ;
    if (!m_hDBFileHandle.good()) {
        return  -4;
    }

	if (m_bIsBigEnd)
	{
		pstManagerHeader->unFrameSize = _V_GET_LITTLE_LONG (&pstManagerHeader->unFrameSize) ;
		pstManagerHeader->unRankInfo = _V_GET_LITTLE_LONG (&pstManagerHeader->unRankInfo) ;
		pstManagerHeader->unRegionCnt = _V_GET_LITTLE_LONG (&pstManagerHeader->unRegionCnt) ;
		pstManagerHeader->unRegionIdxSize = _V_GET_LITTLE_LONG (&pstManagerHeader->unRegionIdxSize) ;
		pstManagerHeader->pstRegionIdxTable = _V_GET_LITTLE_LONG (&pstManagerHeader->pstRegionIdxTable) ;
	}

	pstRegionIdxTable = (DB_CalcRegion_Idx_t*)
		(pbtCalcRegionManagerHeader + (u_int)(pstManagerHeader->pstRegionIdxTable) );

	if (m_bIsBigEnd)
	{
		for (i = 0; i < pstManagerHeader->unRegionCnt ; i++)
		{
			pstRegionIdxTable->unRegionOffset = _V_GET_LITTLE_LONG (
				&(pstRegionIdxTable->unRegionOffset) );
			pstRegionIdxTable->unUnCompressedRegionOffset = _V_GET_LITTLE_LONG (
				&(pstRegionIdxTable->unUnCompressedRegionOffset) );
			pstRegionIdxTable->unRegionSize = _V_GET_LITTLE_LONG (
				&(pstRegionIdxTable->unRegionSize) );
			pstRegionIdxTable->unCompressedRegionSize = _V_GET_LITTLE_LONG (
				&(pstRegionIdxTable->unCompressedRegionSize) );

			pstRegionIdxTable = (DB_CalcRegion_Idx_t*)
				( (Byte*)pstRegionIdxTable + pstManagerHeader->unRegionIdxSize );
		}
	}

	return 0;
}

int main() {
    std::cout << "start test ..." << std::endl;
    std::string usPathFileName = "/home/tiger/cpp/fstream/dbfile/103.rp";
    DBParser dbParser;
    dbParser.Init (usPathFileName);
    u_int unHeaderSize = 0;
    u_int unNameFrameSize = 0;
    u_int unDistrictFrameSize = 0;
    std::cout << dbParser.GetHeaderSize(&unHeaderSize) << " " << unHeaderSize << std::endl;
    if (unHeaderSize > 0) {
        DB_Header_t stHeaderInfo;
        u_int size = sizeof(stHeaderInfo);
        std::cout << size << "   " << unHeaderSize << std::endl;
        unHeaderSize > size ? unHeaderSize = size : 0;
        std::cout << dbParser.GetHeader(unHeaderSize, &stHeaderInfo) << std::endl;
        std::cout << stHeaderInfo.cFormatVer << std::endl;
	    std::cout << stHeaderInfo.cDataVer << std::endl;
	    std::cout << stHeaderInfo.cAuthor << std::endl;
	    std::cout << stHeaderInfo.cDate << std::endl;
    }
    std::cout << dbParser.GetNameFrameSize(&unNameFrameSize) << " " << unNameFrameSize << std::endl;
    if (unNameFrameSize > 0) {
		DB_NameFrame_t pstNameFrame;
        //dbParser.GetNameFrame(, , );
    }
    std::cout << dbParser.GetDistrictFrameSize(&unDistrictFrameSize) << " " << unDistrictFrameSize << std::endl;
    return 0;
}

编译执行:

g++ -g -o test test.cpp 

strace -ff -o ./out  ./test 

 

1.gcount

原始代码:

 

  系统调用:

 

 结论: 

可以看到gcount是上一次读取字节数,没有对应系统api调用

2.seekg和tellg

 

 结论:

seekg和tellg对应系统调用为lseek

3.read

原始代码:

系统调用:

 结论:

read对应系统调用为read,而且可以知道即使读取4个字节,底层系统api调用是将整个文件进行读取

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Linux下std::ifstream成员函数对应系统调用验证 的相关文章

  • C++:无法使用scoped_allocator_adaptor传播polymorphic_allocator

    我有一个vector
  • 如何在 Unity 中从 RenderTexture 访问原始数据

    问题的简短版本 我正在尝试访问 Unity 中 RenderTexture 的内容 我一直在使用 Graphics Blit 使用自己的材质进行绘制 Graphics Blit null renderTexture material 我的材
  • 模板类的不明确多重继承

    我有一个真实的情况 可以总结为以下示例 template lt typename ListenerType gt struct Notifier void add listener ListenerType struct TimeListe
  • 如何在C++中实现模板类协变?

    是否可以以这样一种方式实现类模板 如果模板参数相关 一个对象可以转换为另一个对象 这是一个展示这个想法的例子 当然它不会编译 struct Base struct Derived Base template
  • FFMPEG Seeking 带来音频伪影

    我正在使用 ffmpeg 实现音频解码器 在读取音频甚至搜索已经可以工作时 我无法找到一种在搜索后清除缓冲区的方法 因此当应用程序在搜索后立即开始读取音频时 我没有任何工件 avcodec flush buffers似乎对内部缓冲区没有任何
  • 为什么 POSIX 允许在只读模式下超出现有文件结尾 (fseek) 进行搜索

    为什么寻找文件结尾很有用 为什么 POSIX 让我们像示例中那样在以只读方式打开的文件中进行查找 c http en cppreference com w c io fseek http en cppreference com w c io
  • 写入和读取文本文件 - C# Windows 通用平台应用程序 Windows 10

    有用 但在显示任何内容之前 您必须在文本框中输入内容 我想那是因为我使用了 TextChanged 事件处理程序 如果我希望它在没有用户交互的情况下显示文本文件的内容 我应该使用哪个事件处理程序 因此 我想在按下按钮时将一些数据写入 C W
  • HttpClient 像浏览器一样请求

    当我通过 HttpClient 类调用网站 www livescore com 时 我总是收到错误 500 可能服务器阻止了来自 HttpClient 的请求 1 还有其他方法可以从网页获取html吗 2 如何设置标题来获取html内容 当
  • 基于范围的 for 循环中的未命名循环变量?

    有没有什么方法可以不在基于范围的 for 循环中 使用 循环变量 同时也避免编译器发出有关未使用它的警告 对于上下文 我正在尝试执行以下操作 我启用了 将警告视为错误 并且我不想进行像通过在某处毫无意义地提及变量来强制 使用 变量这样的黑客
  • 在 ASP.Net Core 2.0 中导出到 Excel

    我曾经使用下面的代码在 ASP NET MVC 中将数据导出到 Excel Response AppendHeader content disposition attachment filename ExportedHtml xls Res
  • A* 之间的差异 pA = 新 A;和 A* pA = 新 A();

    在 C 中 以下两个动态对象创建之间的确切区别是什么 A pA new A A pA new A 我做了一些测试 但似乎在这两种情况下 都调用了默认构造函数 并且仅调用了它 我正在寻找性能方面的任何差异 Thanks If A是 POD 类
  • 如何在 Team Foundation 上强制发表有意义的签入评论?

    我有一个开发团队有一个坏习惯 他们写道poor签入评论 当我们必须在团队基础上查看文件的历史记录时 这使得它成为一场噩梦 我已经启用了变更集评论政策 这样他们甚至可以在签到时留下评论 否则他们不会 我们就团队的工作质量进行了一些讨论 他们很
  • 初始化变量的不同方式

    在 C 中初始化变量有多种方法 int z 3 与 int 相同z 3 Is int z z 3 same as int z z 3 您可以使用 int z z 3 Or just int z 3 Or int z 3 Or int z i
  • 可空属性与可空局部变量

    我对以下行为感到困惑Nullable types class TestClass public int value 0 TestClass test new TestClass Now Nullable GetUnderlyingType
  • 将应用程序从 Microsoft Access 迁移到 VB 或 C#.NET

    我目前正试图说服管理层需要将我们的应用程序之一移植到 NET 该应用程序已经发展成为 Access 中的一个庞然大物 SQL 后端 拥有 700 个链接表 650 个表单 子表单 130 个模块和 850 个查询 我几乎知道这样做的所有主要
  • EPPlus Excel 更改单元格颜色

    我正在尝试将给定单元格的颜色设置为另一个单元格的颜色 该单元格已在模板中着色 但worksheet Cells row col Style Fill BackgroundColor似乎没有get财产 是否可以做到这一点 或者我是否必须在互联
  • 已过时 - OpenCV 的错误模式

    我正在使用 OpenCV 1 进行一些图像处理 并且对 cvSetErrMode 函数 它是 CxCore 的一部分 感到困惑 OpenCV 具有三种错误模式 叶 调用错误处理程序后 程序终止 Parent 程序没有终止 但错误处理程序被调
  • ListDictionary 类是否有通用替代方案?

    我正在查看一些示例代码 其中他们使用了ListDictionary对象来存储少量数据 大约 5 10 个对象左右 但这个数字可能会随着时间的推移而改变 我使用此类的唯一问题是 与我所做的其他所有事情不同 它不是通用的 这意味着 如果我在这里
  • C++ 成员函数中的“if (!this)”有多糟糕?

    如果我遇到旧代码if this return 在应用程序中 这种风险有多严重 它是一个危险的定时炸弹 需要立即在应用程序范围内进行搜索和销毁工作 还是更像是一种可以悄悄留在原处的代码气味 我不打算writing当然 执行此操作的代码 相反
  • 将 viewbag 从操作控制器传递到部分视图

    我有一个带有部分视图的 mvc 视图 控制器中有一个 ActionResult 方法 它将返回 PartialView 因此 我需要将 ViewBag 数据从 ActionResult 方法传递到 Partial View 这是我的控制器

随机推荐

  • USB fastboot

    1 Samsung fastboot flashing unlock 2 bootloader增加解锁密码 diff git a app aboot aboot c b app aboot aboot c index e4d46e4 1b4
  • win10安装.NET Framework 4.5.2时会提示:这台计算机中已经安装了 .NET Framework 4.5.2 或版本更高的更新

    问题现象 win10安装 NET Framework 4 5 2时会提示 这台计算机中已经安装了 NET Framework 4 5 2 或版本更高的更新 问题原因 Win10系统自带的 net framework版本为4 7 问题解决 1
  • 1352--奖金(拓扑排序)

    输入样例 2 1 1 2 输出样例 201 解析 拓扑排序 判断是否存在结果 include
  • 鸢尾花分类

    鸢尾花数据集 鸢尾花数据集包含四个特征和一个标签 这四个特征确定了单株鸢尾花的下列植物学特征 花萼长度 花萼宽度 花瓣长度 花瓣宽度 我们的模型会将这些特征表示为float32数值数据 该标签确定了鸢尾花品种 品种必须是下列任意一种 山鸢尾
  • 交流耦合与直流耦合

    交流耦合 AC Coupling 就是通过隔直电容耦合 去掉了直流分量 直流耦合 DC Coupling 就是直通 交流直流一起过 并不是去掉了交流分量 比如在3V的直流电平上叠加一个1Vpp的弦波 如果用直流耦合 看到的是以3V为基准 0
  • Codeblocks+MinGW+wxWidgets搭建方法

    Code Block MinGW 和 wxWidgets 分别是三个著名的开源项目 分别是 IDE 编译器和界面库 由这三样搭建起来的全开源纯c 开发环境 功能不逊色于Visual C 由于是开源的 这样的环境还是免费的 并且是跨平台的 下
  • [管理与领导-73]:IT基层管理者 - 辅助技能 - 4- 职业发展规划 - 如何持续提升自我

    目录 一 能力三核 1 1 专业知识能力 1 2 通用管理能力 1 3 优秀品质能力 二 能力发展策略 三 学习的四种渠道 四 有效的刻意练习 一 能力三核 1 1 专业知识能力 专业知识能力是指在特定领域或行业中所掌握的专业知识和技能 它
  • Ubuntu空间不足,如何扩容

    目录 1 硬盘操作步骤 2 Ubuntu命令操作 安装分区管理工具 3 分区结果展示 1 硬盘操作步骤 最近发现Ubuntu空间不足 怎么去扩容呢 第一步 点击 硬盘 第二步 点击 扩展 第三步 修改 最大磁盘容量大小 选择一个自己认为比较
  • 一. k8s-基础概念

    1 kubernetes是什么 Kubernetes 是一个可移植 可扩展的开源容器编排系统 主要用于自动化部署 扩展和管理容器应用 提供资源调度 部署管理 服务发现 扩容缩容 监控等功能 对于负载均衡 服务发现 高可用 滚动升级 自动伸缩
  • 303. Range Sum Query - Immutable dynamic programming

    Given an integer array nums find the sum of the elements between indices i and j i j inclusive Example Given nums 2 0 3
  • 多电平双向DC/DC直流变换器的工作原理(以三电平为例子)

    多电平双向DCDC变换器的工作原理 一 所用论文和参考文献 1 1 主要是中文的文献 二 工作原理和重要概念 2 1 飞跨电容的作用 2 2 三电平的工作原理 1 3 多电平的优点 二 一些注意点 2 1 电感电流的变化 2 2 多飞跨电容
  • UE4 c++动态加载Ui并添加到窗口

    创建界面并且添加到窗口用蓝图创建的话 比较简单 本篇博文就不介绍了 有时候需要用C 添加已经创建好的界面蓝图到窗口 下面就简单介绍一下怎么用C 的方法添加 涉及到动态加载 FString UiPath TEXT Script UMGEdit
  • FPGA设计:制作一个频率计

    这次把自己做过的一个频率计拿出来跟大家分享一下 项目采用VHDL语言来编写 一 功能介绍 对信号源输入信号的频率进行正确测量并显示 测量范围 0 9999Hz 测量精度 1Hz 测量误差 1Hz 因为用的FPGA板只有四个数码管 所以就采用
  • 84.Robot Framework简介及安装验证方法

    文章目录 requirements 简介 Robot Framework架构 安装Robot Framework 转载请注明原始链接 https blog csdn net a464057216 article details 104369
  • 距离向量(DV)算法的问题

    上一篇将了DV协议的基本内容 DV算法固然简单易懂 但应用于实际后 人们很快发现这种算法在某些特定情况下是会出现一些致命的问题的 在这篇文章中 我们来讨论下这些问题及其解决方法 分割线 选路环路 routing loop 和计数到无穷 co
  • 嵌入式毕业设计选题推荐 题目汇总

    文章目录 1前言 2 如何选题 2 1 不要给自己挖坑 2 2 难度把控 2 3 如何命名题目 3 单片机 嵌入式 选题大全 3 1 嵌入式方向 3 2 算法方向 3 3 移动通信方向 3 4 学长作品展示 4 最后 1前言 近期不少学弟学
  • linux开机dracut界面_CentOS启动报错dracut Warning: Boot has failed的解决方法

    CentOS无法启动 启动分区无法找到 然后就报了个堆栈信息 ACPI wmi Mapper loaded dracut Warning No root device block dev sda4 found dracut Warning
  • 数据分析课程笔记(四)pandas、series、dataframe、索引数据和缺失数据处理

    数据分析课程笔记 pandas 为什么要学习pandas 常见数据类型 创建series Series切片和索引 Series的索引和值 读取外部数据 DataFrame 索引数据 loc iloc 布尔索引 字符串方法 缺失数据处理 pa
  • map/unordered_map原理和使用整理

    1 结论 新版的hash map都是unordered map了 这里只说unordered map和map 运行效率方面 unordered map最高 而map效率较低但 提供了稳定效率和有序的序列 占用内存方面 map内存占用略低 u
  • Linux下std::ifstream成员函数对应系统调用验证

    最近在分析离线数据使用时的bug 发现代码中对std ifstream成员函数使用存在疑问 所以就写了个简单测试程序来分析std ifstream成员函数对应那些系统调用 目录 1 gcount 2 seekg和tellg 3 read 代