全志 视频输入组件的使用

embedded/2025/1/31 1:20:24/

1.启动MPP和Glog库

示例代码:

log_init(argv[0], &stGLogConfig);MPP_SYS_CONF_S stSysConf;
memset(&stSysConf, 0, sizeof(MPP_SYS_CONF_S));
stSysConf.nAlignWidth = 32;
AW_MPI_SYS_SetConf(&stSysConf);
ret = AW_MPI_SYS_Init();

2.获取配置文件信息

parseCmdLine(pContext, argc, argv)

3.初始化ISP

AW_MPI_SYS_Init();

4.创建VI组件

4.1 配置VI组件信息

pContext->mViAttr.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
pContext->mViAttr.memtype = V4L2_MEMORY_MMAP;
pContext->mViAttr.format.pixelformat = map_PIXEL_FORMAT_E_to_V4L2_PIX_FMT(pContext->mConfigPara.mPicFormat);
pContext->mViAttr.format.field = V4L2_FIELD_NONE;
pContext->mViAttr.format.width = pContext->mConfigPara.mPicWidth;
pContext->mViAttr.format.height = pContext->mConfigPara.mPicHeight;
pContext->mViAttr.nbufs = 3;//5;
pContext->mViAttr.nplanes = 2;
pContext->mViAttr.fps = pContext->mConfigPara.mFrameRate;
pContext->mViAttr.use_current_win = 0;
pContext->mFirstVippRunFlag = true;
pContext->mViAttr.wdr_mode = 0;
pContext->mViAttr.capturemode = V4L2_MODE_VIDEO;
pContext->mViAttr.drop_frame_num = 0;
  1. pContext->mViAttr.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;

    • 设置缓冲区类型为视频捕获多平面模式(V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)。多平面模式通常用于支持多个数据平面的设备,可能是在捕获时同时传输多个图像平面(例如,YUV格式的不同平面)。
  2. pContext->mViAttr.memtype = V4L2_MEMORY_MMAP;

    • 设置缓冲区内存类型为V4L2_MEMORY_MMAP,即通过内存映射来管理缓冲区。这是与内存映射I/O接口结合使用的方式,用于通过映射内存区域访问数据。
  3. pContext->mViAttr.format.pixelformat = map_PIXEL_FORMAT_E_to_V4L2_PIX_FMT(pContext->mConfigPara.mPicFormat);

    • 设置捕获图像的像素格式。map_PIXEL_FORMAT_E_to_V4L2_PIX_FMT是一个函数,它将应用程序中的图像格式(如YUV420等)映射到V4L2标准格式(如V4L2_PIX_FMT_YUYVV4L2_PIX_FMT_NV12等)。
  4. pContext->mViAttr.format.field = V4L2_FIELD_NONE;

    • 设置捕获的字段类型为V4L2_FIELD_NONE,表示图像不使用交错的场。交错场模式通常用于电视信号和视频播放中,V4L2_FIELD_NONE意味着逐行扫描模式。
  5. pContext->mViAttr.format.width = pContext->mConfigPara.mPicWidth;

    • 设置捕获图像的宽度,来源于配置参数中的mPicWidth
  6. pContext->mViAttr.format.height = pContext->mConfigPara.mPicHeight;

    • 设置捕获图像的高度,来源于配置参数中的mPicHeight
  7. pContext->mViAttr.nbufs = 3;

    • 设置视频捕获的缓冲区数量为3。nbufs通常是视频缓冲区的数量,设置合适的缓冲区数量对于流畅的捕获和处理非常重要。
  8. pContext->mViAttr.nplanes = 2;

    • 设置每个视频缓冲区的平面数为2,通常在YUV格式下,图像会被分成多个平面(例如,一个Y平面和一个UV平面)。nplanes表示每个缓冲区中的平面数。
  9. pContext->mViAttr.fps = pContext->mConfigPara.mFrameRate;

    • 设置视频捕获的帧率,来源于配置参数中的mFrameRate
  10. pContext->mViAttr.use_current_win = 0;

    • 设置是否使用当前窗口。通常这是与视频捕获窗口的配置相关,0表示不使用当前窗口。
  11. pContext->mFirstVippRunFlag = true;

    • 设置一个标志,表示这是第一次启动视频捕获过程,可能用于初始化相关资源。
  12. pContext->mViAttr.wdr_mode = 0;

    • 设置宽动态范围(WDR)模式为0,表示没有启用WDR功能。WDR用于在具有较大亮度范围的场景中提高图像质量。
  13. pContext->mViAttr.capturemode = V4L2_MODE_VIDEO;

    • 设置捕获模式为V4L2_MODE_VIDEO,表示采用标准的视频捕获模式。
  14. pContext->mViAttr.drop_frame_num = 0;

    • 设置丢帧数为0,表示不丢弃任何帧。

4.2 创建VIPP

AW_MPI_VI_CreateVipp(nVippIndex);

4.3 设置VIPP属性

AW_MPI_VI_SetVippAttr(nVippIndex, &pContext->mViAttr);

4.4 启动VIPP

AW_MPI_VI_EnableVipp(nVippIndex);

4.5 配置虚通道信息

VirViChnInfo *pChnInfo = &pContext->mVirViChnArray[nVippIndex][virvi_chn];
memset(pChnInfo, 0, sizeof(VirViChnInfo));
pChnInfo->mVipp = nVippIndex;
pChnInfo->mVirChn = virvi_chn;
pChnInfo->mMilliSec = 5000;  // 2000;
pChnInfo->mCaptureFrameCount = pContext->mConfigPara.mFrameCountStep1;

4.6 创建虚通道

AW_MPI_VI_CreateVirChn(ViDev, ViCh, pAttr);

4.7 设置虚通道属性

AW_MPI_VI_SetVirChnAttr(ViDev, ViCh, pAttr);

4.8 启动虚通道

AW_MPI_VI_EnableVirChn(ViDev, ViCh);

5.获取图像帧

5.1 获取图像数据

AW_MPI_VI_GetFrame(ViDev, ViCh, &pCap->mFrameInfo, pCap->mMilliSec))

5.2 释放图像帧

AW_MPI_VI_ReleaseFrame(ViDev, ViCh, &pCap->mFrameInfo);

6.停止并销毁VI组件

6.1 关闭虚通道

AW_MPI_VI_DisableVirChn(ViDev, ViCh);

6.2 关闭VIPP

AW_MPI_VI_DisableVipp(nVippIndex);

6.3 销毁VIPP

AW_MPI_VI_DestroyVipp(nVippIndex);

6.4 停止ISP

AW_MPI_ISP_Stop();

7.退出MPP

AW_MPI_SYS_Exit();

8.完整源码


#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>#include <utils/plat_log.h>
#include "media/mpi_sys.h"
#include "media/mm_comm_vi.h"
#include "media/mpi_vi.h"
#include "media/mpi_isp.h"
#include <mpi_videoformat_conversion.h>#include <confparser.h>
#include "sample_vi_reset.h"
#include "sample_vi_reset_config.h"#define TEST_FLIP (0)
int hal_virvi_start(VI_DEV ViDev, VI_CHN ViCh, void *pAttr)
{ERRORTYPE ret = -1;ret = AW_MPI_VI_CreateVirChn(ViDev, ViCh, pAttr);if(ret < 0){aloge("Create VI Chn failed,VIDev = %d,VIChn = %d",ViDev,ViCh);return ret ;}ret = AW_MPI_VI_SetVirChnAttr(ViDev, ViCh, pAttr);if(ret < 0){aloge("Set VI ChnAttr failed,VIDev = %d,VIChn = %d",ViDev,ViCh);return ret ;}ret = AW_MPI_VI_EnableVirChn(ViDev, ViCh);if(ret < 0){aloge("VI Enable VirChn failed,VIDev = %d,VIChn = %d",ViDev,ViCh);return ret ;}return 0;
}int hal_virvi_end(VI_DEV ViDev, VI_CHN ViCh)
{int ret = -1;ret = AW_MPI_VI_DisableVirChn(ViDev, ViCh);if(ret < 0){aloge("Disable VI Chn failed,VIDev = %d,VIChn = %d",ViDev,ViCh);return ret ;}ret = AW_MPI_VI_DisableVirChn(ViDev, ViCh);if(ret < 0){aloge("Destory VI Chn failed,VIDev = %d,VIChn = %d",ViDev,ViCh);return ret ;}return 0;
}static int parseCmdLine(SampleViResetContext *pContext, int argc, char** argv)
{int ret = -1;alogd("argc=%d", argc);if (argc != 3){printf("CmdLine param:\n""\t-path ./sample_CodecParallel.conf\n");return -1;}while (*argv){if (!strcmp(*argv, "-path")){argv++;if (*argv){ret = 0;if (strlen(*argv) >= MAX_FILE_PATH_SIZE){aloge("fatal error! file path[%s] too long:!", *argv);}if (pContext){strncpy(pContext->mCmdLinePara.mConfigFilePath, *argv, MAX_FILE_PATH_SIZE-1);pContext->mCmdLinePara.mConfigFilePath[MAX_FILE_PATH_SIZE-1] = '\0';}}}else if(!strcmp(*argv, "-h")){printf("CmdLine param:\n""\t-path ./sample_CodecParallel.conf\n");break;}else if (*argv){argv++;}}return ret;
}static ERRORTYPE LoadSampleViResetConfig(SampleViResetConfig *pConfig, const char *conf_path)
{if (NULL == pConfig){aloge("pConfig is NULL!");return FAILURE;}if (NULL == conf_path){aloge("user not set config file!");return FAILURE;}pConfig->mTestCount = 0;pConfig->mFrameCountStep1 = 300;pConfig->mbRunIsp = true;pConfig->mIspDev = 0;pConfig->mVippStart = 0;pConfig->mVippEnd = 0;pConfig->mPicWidth = 1920;pConfig->mPicHeight = 1080;pConfig->mSubPicWidth = 640;pConfig->mSubPicHeight = 360;pConfig->mFrameRate = 20;pConfig->mPicFormat = MM_PIXEL_FORMAT_YVU_SEMIPLANAR_420;CONFPARSER_S stConfParser;if(0 > createConfParser(conf_path, &stConfParser)){aloge("load conf fail!");return FAILURE;}pConfig->mTestCount = GetConfParaInt(&stConfParser, SAMPLE_VI_RESET_TEST_COUNT, 0);alogd("mTestCount=%d", pConfig->mTestCount);pConfig->mVippStart = GetConfParaInt(&stConfParser, SAMPLE_VI_RESET_VIPP_ID_START, 0);pConfig->mVippEnd = GetConfParaInt(&stConfParser, SAMPLE_VI_RESET_VIPP_ID_END, 0);alogd("vi config: vipp scope=[%d,%d], captureSize:[%dx%d,%dx%d] frameRate:%d, pixelFormat:0x%x",pConfig->mVippStart, pConfig->mVippEnd, pConfig->mPicWidth, pConfig->mPicHeight, pConfig->mSubPicWidth, pConfig->mSubPicHeight, pConfig->mFrameRate, pConfig->mPicFormat);destroyConfParser(&stConfParser);return SUCCESS;
}static void *GetCSIFrameThread(void *pArg)
{VI_DEV ViDev;VI_CHN ViCh;int ret = 0;int i = 0, j = 0;VirViChnInfo *pCap = (VirViChnInfo*)pArg;ViDev = pCap->mVipp;ViCh = pCap->mVirChn;alogd("Cap threadid=0x%lx, ViDev = %d, ViCh = %d", pCap->mThid, ViDev, ViCh);int nFlipValue = 0;int nFlipTestCnt = 0;while (pCap->mCaptureFrameCount > j){if ((ret = AW_MPI_VI_GetFrame(ViDev, ViCh, &pCap->mFrameInfo, pCap->mMilliSec)) != 0){alogw("Vipp[%d,%d] Get Frame failed!", ViDev, ViCh);continue;}i++;if (i % 20 == 0){time_t now;struct tm *timenow;time(&now);timenow = localtime(&now);alogd("Cap threadid=0x%lx, ViDev=%d, VirVi=%d, mpts=%lld; local time is %s", pCap->mThid, ViDev, ViCh, pCap->mFrameInfo.VFrame.mpts, asctime(timenow));
#if 0FILE *fd;char filename[128];sprintf(filename, "/tmp/%dx%d_%d.yuv",pCap->pstFrameInfo.VFrame.mWidth,pCap->pstFrameInfo.VFrame.mHeight,i);fd = fopen(filename, "wb+");fwrite(pCap->pstFrameInfo.VFrame.mpVirAddr[0],pCap->pstFrameInfo.VFrame.mWidth * pCap->pstFrameInfo.VFrame.mHeight,1, fd);fwrite(pCap->pstFrameInfo.VFrame.mpVirAddr[1],pCap->pstFrameInfo.VFrame.mWidth * pCap->pstFrameInfo.VFrame.mHeight >> 1,1, fd);fclose(fd);
#endif}AW_MPI_VI_ReleaseFrame(ViDev, ViCh, &pCap->mFrameInfo);j++;
#if TEST_FLIPif(j == pCap->mCaptureFrameCount){j = 0;if(0 == ViDev){nFlipValue = !nFlipValue;nFlipTestCnt++;AW_MPI_VI_SetVippMirror(ViDev, nFlipValue);AW_MPI_VI_SetVippFlip(ViDev, nFlipValue);alogd("vipp[%d] mirror and flip:%d, test count:%d begin.", ViDev, nFlipValue, nFlipTestCnt);}}
#endif}return NULL;
}
int RunOneVipp(VI_DEV nVippIndex, SampleViResetContext *pContext)
{ERRORTYPE ret = SUCCESS;/*Set VI Channel Attribute*/memset(&pContext->mViAttr, 0, sizeof(VI_ATTR_S));pContext->mViAttr.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;pContext->mViAttr.memtype = V4L2_MEMORY_MMAP;pContext->mViAttr.format.pixelformat = map_PIXEL_FORMAT_E_to_V4L2_PIX_FMT(pContext->mConfigPara.mPicFormat);pContext->mViAttr.format.field = V4L2_FIELD_NONE;alogd("nVippIndex=%d", nVippIndex);if(0 == nVippIndex){pContext->mViAttr.format.width = pContext->mConfigPara.mPicWidth;pContext->mViAttr.format.height = pContext->mConfigPara.mPicHeight;}else{pContext->mViAttr.format.width = pContext->mConfigPara.mSubPicWidth;pContext->mViAttr.format.height = pContext->mConfigPara.mSubPicHeight;}pContext->mViAttr.nbufs = 3;//5; pContext->mViAttr.nplanes = 2;pContext->mViAttr.fps = pContext->mConfigPara.mFrameRate;/* update configuration anyway, do not use current configuration */if(false == pContext->mFirstVippRunFlag){pContext->mViAttr.use_current_win = 0; //更新视频输入属性pContext->mFirstVippRunFlag = true;}else{pContext->mViAttr.use_current_win = 1;}pContext->mViAttr.wdr_mode = 0;pContext->mViAttr.capturemode = V4L2_MODE_VIDEO;pContext->mViAttr.drop_frame_num = 0;ret = AW_MPI_VI_CreateVipp(nVippIndex);if(ret != SUCCESS){aloge("fatal error! create vipp[%d] fail[0x%x]", nVippIndex, ret);}ret = AW_MPI_VI_SetVippAttr(nVippIndex, &pContext->mViAttr);if(ret != SUCCESS){aloge("fatal error! set vipp attr[%d] fail[0x%x]", nVippIndex, ret);}if(pContext->mConfigPara.mbRunIsp && false == pContext->mbIspRunningFlag){ret = AW_MPI_ISP_Run(pContext->mConfigPara.mIspDev);if(ret != SUCCESS){aloge("fatal error! isp[%d] run fail[0x%x]", pContext->mConfigPara.mIspDev, ret);}pContext->mbIspRunningFlag = true;}ret = AW_MPI_VI_EnableVipp(nVippIndex);if(ret != SUCCESS){aloge("fatal error! enable vipp[%d] fail[0x%x]", nVippIndex, ret);}VI_CHN virvi_chn = 0;for (virvi_chn = 0; virvi_chn < 1 /*MAX_VIR_CHN_NUM*/; virvi_chn++){VirViChnInfo *pChnInfo = &pContext->mVirViChnArray[nVippIndex][virvi_chn];memset(pChnInfo, 0, sizeof(VirViChnInfo));pChnInfo->mVipp = nVippIndex;pChnInfo->mVirChn = virvi_chn;pChnInfo->mMilliSec = 5000;  // 2000; 等待时间为5000毫秒(5秒)pChnInfo->mCaptureFrameCount = pContext->mConfigPara.mFrameCountStep1;//指定捕获帧的计数ret = hal_virvi_start(nVippIndex, virvi_chn, NULL);//启动虚通道if(ret != 0){aloge("virvi start failed!");}pChnInfo->mThid = 0;ret = pthread_create(&pChnInfo->mThid, NULL, GetCSIFrameThread, (void *)pChnInfo);if(0 == ret){alogd("pthread create success, vipp[%d], virChn[%d]", pChnInfo->mVipp, pChnInfo->mVirChn);}else{aloge("fatal error! pthread_create failed, vipp[%d], virChn[%d]", pChnInfo->mVipp, pChnInfo->mVirChn);}}return ret;
}int DestroyOneVipp(VI_DEV nVippIndex, SampleViResetContext *pContext)
{int ret = 0;VI_CHN virvi_chn = 0;for (virvi_chn = 0; virvi_chn < 1; virvi_chn++){ret = hal_virvi_end(nVippIndex, virvi_chn);if(ret != 0){aloge("fatal error! virvi[%d,%d] end failed!", nVippIndex, virvi_chn);}}ret = AW_MPI_VI_DisableVipp(nVippIndex);if(ret != SUCCESS){aloge("fatal error! disable vipp[%d] fail", nVippIndex);}ret = AW_MPI_VI_DestroyVipp(nVippIndex);if(ret != SUCCESS){aloge("fatal error! destroy vipp[%d] fail", nVippIndex);}alogd("vipp[%d] is destroyed!", nVippIndex);return ret;
}int main(int argc, char *argv[])
{int result = 0;ERRORTYPE ret;int virvi_chn;GLogConfig stGLogConfig = {.FLAGS_logtostderr = 1,.FLAGS_colorlogtostderr = 1,.FLAGS_stderrthreshold = _GLOG_INFO,.FLAGS_minloglevel = _GLOG_INFO,.FLAGS_logbuflevel = -1,.FLAGS_logbufsecs = 0,.FLAGS_max_log_size = 1,.FLAGS_stop_logging_if_full_disk = 1,};strcpy(stGLogConfig.LogDir, "/tmp/log");strcpy(stGLogConfig.InfoLogFileNameBase, "LOG-");strcpy(stGLogConfig.LogFileNameExtension, "IPC-");log_init(argv[0], &stGLogConfig);alogd("app:[%s] begin! time=%s, %s", argv[0], __DATE__, __TIME__);SampleViResetContext *pContext = (SampleViResetContext*)malloc(sizeof(SampleViResetContext));if(NULL == pContext){aloge("fatal error! malloc fail!");return -1;}memset(pContext, 0, sizeof(SampleViResetContext));/* parse command line param */char *pConfigFilePath = NULL;if (parseCmdLine(pContext, argc, argv) != SUCCESS){aloge("fatal error! parse cmd line fail");result = -1;goto _exit;}pConfigFilePath = pContext->mCmdLinePara.mConfigFilePath;/* parse config file. */if(LoadSampleViResetConfig(&pContext->mConfigPara, pConfigFilePath) != SUCCESS){aloge("fatal error! no config file or parse conf file fail");result = -1;goto _exit;}MPP_SYS_CONF_S stSysConf;memset(&stSysConf, 0, sizeof(MPP_SYS_CONF_S));stSysConf.nAlignWidth = 32;AW_MPI_SYS_SetConf(&stSysConf);ret = AW_MPI_SYS_Init();if (ret != SUCCESS){aloge("sys Init failed!");goto _exit;}while (pContext->mTestNum < pContext->mConfigPara.mTestCount || 0 == pContext->mConfigPara.mTestCount){alogd("======================================");alogd("Auto Test count : %d. (MaxCount==%d)", pContext->mTestNum, pContext->mConfigPara.mTestCount);//system("cat /proc/meminfo | grep Committed_AS");alogd("======================================");VI_DEV nVippIndex;for(nVippIndex = pContext->mConfigPara.mVippStart; nVippIndex <= pContext->mConfigPara.mVippEnd; nVippIndex++){RunOneVipp(HVIDEO(nVippIndex, 0), pContext);}for(nVippIndex = pContext->mConfigPara.mVippStart; nVippIndex <= pContext->mConfigPara.mVippEnd; nVippIndex++){for (virvi_chn = 0; virvi_chn < 1; virvi_chn++){pthread_join(pContext->mVirViChnArray[HVIDEO(nVippIndex, 0)][virvi_chn].mThid, NULL);alogd("vipp[%d]virChn[%d] capture thread is exit!", HVIDEO(nVippIndex, 0), virvi_chn);}}for(nVippIndex = pContext->mConfigPara.mVippStart; nVippIndex <= pContext->mConfigPara.mVippEnd; nVippIndex++){DestroyOneVipp(HVIDEO(nVippIndex, 0), pContext);}if(pContext->mbIspRunningFlag){AW_MPI_ISP_Stop(pContext->mConfigPara.mIspDev);alogd("isp[%d] is stopped!", pContext->mConfigPara.mIspDev);pContext->mbIspRunningFlag = false;}pContext->mTestNum++;pContext->mFirstVippRunFlag = false;alogd("[%d] test time is done!", pContext->mTestNum);}_exit:free(pContext);alogd("%s test result: %s", argv[0], ((0==result) ? "success" : "fail"));return result;
}


http://www.ppmy.cn/embedded/157718.html

相关文章

MFC开发,给对话框添加垂直滚动条并解决鼠标滚动响应的问题

无论在使用QT或者MFC进行界面开发时&#xff0c;都会出现在一个对话框里面存在好多的选项&#xff0c;导致对话框变得非常长或者非常大&#xff0c;就会显现的不美观&#xff0c;在这种情况下通常是添加一个页面的滚动条来解决这个问题&#xff0c;下面我们就来介绍给MFC的对话…

蓝桥杯python语言基础(4)——基础数据结构(上)

目录 一、列表与元组 &#xff08;一&#xff09;列表 &#xff08;二&#xff09;操作列表 &#xff08;三&#xff09;元组 习题P502 习题P497 二、字符串 &#xff08;一&#xff09;字符串的基本操作 &#xff08;二&#xff09;字符串的常用方法 &#xff08;三&…

从0到1:C++ 开启游戏开发奇幻之旅(一)

目录 为什么选择 C 进行游戏开发 性能卓越 内存管理精细 跨平台兼容性强 搭建 C 游戏开发环境 集成开发环境&#xff08;IDE&#xff09; Visual Studio CLion 图形库 SDL&#xff08;Simple DirectMedia Layer&#xff09; SFML&#xff08;Simple and Fast Multim…

知网爬虫,作者、摘要、题目、发表期刊等主要内容的获取

爬取知网内容的详细过程 爬取知网内容需要考虑多个因素,包括网站的结构、反爬虫机制等。以下是一个详细的步骤和代码实现,帮助你使用Python爬取知网上的论文信息,包括作者、摘要、题目、发表期刊等主要内容。 1. 数据准备 首先,需要准备一些基础数据,如知网的URL、请求…

基于fpga技术的脉冲信号源设计(论文+源码)

1系统总体设计 本次课题为基于FPGA的质谱脉冲信号源.&#xff0c;主要结合FPGA技术进行设计&#xff0c;整个系统的框图如图3.1所示&#xff0c;其包括了EP4CE6E22 FPGA控制器&#xff0c;按键&#xff0c;LCDLCD液晶显示&#xff0c;AD9708数模转换电路等器件构成系统的硬件基…

TypeScript 学习 -类型 - 9

声明合并 成员变量合并&#xff1a;成员变量会合并&#xff0c;但类型必须一致。成员函数合并&#xff1a;如果函数签名不同&#xff0c;合并后的函数会是签名的联合类型。接口声明顺序&#xff1a;在同一个接口内按顺序合并&#xff1b;不同接口时&#xff0c;后声明的会覆盖…

Kotlin单例类

什么是单例类&#xff1f; 单例类是在全局上只能创建一个实例的类&#xff0c;其可避免创建重复对象。 单例类实现 Java实现&#xff1a; public calss Singleton {private static Singleton instance;private Singleton() {}public synchronized static Singleton getInst…

vector的使用,以及部分功能的模拟实现(C++)

1.vector的介绍及使用 1.1 vector的介绍 vector是STL容器中的一种常用的容器&#xff0c;和数组类似&#xff0c;由于其大小(size)可变&#xff0c;常用于数组大小不可知的情况下来替代数组。 vector也是一种顺序容器&#xff0c;在内存中连续排列&#xff0c;因此可以通过下标…