当前位置: 首页 > news >正文

HarmonyOS Next开发----使用XComponent自定义绘制

XComponent组件作为一种绘制组件,通常用于满足用户复杂的自定义绘制需求,其主要有两种类型"surface和component。对于surface类型可以将相关数据传入XComponent单独拥有的NativeWindow来渲染画面。

由于上层UI是采用arkTS开发,那么想要使用XComponent的话,就需要一个桥接和native层交互,类似Android的JNI,鸿蒙应用可以使用napi接口来处理js和native层的交互。

1. 编写CMAKELists.txt文件
# the minimum version of CMake.
cmake_minimum_required(VERSION 3.4.1)
project(XComponent) #项目名称set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
#头文件查找路径
include_directories(${NATIVERENDER_ROOT_PATH}${NATIVERENDER_ROOT_PATH}/include
)
# 编译目标so动态库
add_library(nativerender SHAREDsamples/minute_view.cppplugin/plugin_manager.cppcommon/HuMarketMinuteData.cppcommon/MinuteItem.cppnapi_init.cpp
)
# 查找需要的公共库
find_library(# Sets the name of the path variable.hilog-lib# Specifies the name of the NDK library that# you want CMake to locate.hilog_ndk.z
)
#编译so所需要的依赖
target_link_libraries(nativerender PUBLIClibc++.a${hilog-lib}libace_napi.z.solibace_ndk.z.solibnative_window.solibnative_drawing.so
)
2. Napi模块注册
#include <hilog/log.h>
#include "plugin/plugin_manager.h"
#include "common/log_common.h"EXTERN_C_START
static napi_value Init(napi_env env, napi_value exports)
{OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Init", "Init begins");if ((nullptr == env) || (nullptr == exports)) {OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Init", "env or exports is null");return nullptr;}PluginManager::GetInstance()->Export(env, exports);return exports;
}
EXTERN_C_ENDstatic napi_module nativerenderModule = {.nm_version = 1,.nm_flags = 0,.nm_filename = nullptr,.nm_register_func = Init,.nm_modname = "nativerender",.nm_priv = ((void *)0),.reserved = { 0 }
};extern "C" __attribute__((constructor)) void RegisterModule(void)
{napi_module_register(&nativerenderModule);
}

定义napi_module信息,里面包含模块名称(和arkts侧使用时的libraryname要保持一致),加载模块时的回调函数即Init()。然后注册so模块napi_module_register(&nativerenderModule), 接口Init()函数会收到回调,在Init()有两个参数:

  • env: napi上下文环境;
  • exports: 用于挂载native函数将其导出,会通过js引擎绑定到js层的一个js对象;
3.解析XComponent组件的NativeXComponent实例
 if ((env == nullptr) || (exports == nullptr)) {DRAWING_LOGE("Export: env or exports is null");return;}napi_value exportInstance = nullptr;// 用来解析出被wrap了NativeXComponent指针的属性if (napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance) != napi_ok) {DRAWING_LOGE("Export: napi_get_named_property fail");return;}OH_NativeXComponent *nativeXComponent = nullptr;// 通过napi_unwrap接口,解析出NativeXComponent的实例指针if (napi_unwrap(env, exportInstance, reinterpret_cast<void **>(&nativeXComponent)) != napi_ok) {DRAWING_LOGE("Export: napi_unwrap fail");return;}char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {'\0'};uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;if (OH_NativeXComponent_GetXComponentId(nativeXComponent, idStr, &idSize) != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {DRAWING_LOGE("Export: OH_NativeXComponent_GetXComponentId fail");return;}
4.注册XComponent事件回调
void MinuteView::RegisterCallback(OH_NativeXComponent *nativeXComponent) {DRAWING_LOGI("register callback");renderCallback_.OnSurfaceCreated = OnSurfaceCreatedCB;renderCallback_.OnSurfaceDestroyed = OnSurfaceDestroyedCB;renderCallback_.DispatchTouchEvent = nullptr;renderCallback_.OnSurfaceChanged = OnSurfaceChanged;// 注册XComponent事件回调OH_NativeXComponent_RegisterCallback(nativeXComponent, &renderCallback_);
}

在事件回调中可以获取组件的宽高信息:

tatic void OnSurfaceCreatedCB(OH_NativeXComponent *component, void *window) {DRAWING_LOGI("OnSurfaceCreatedCB");if ((component == nullptr) || (window == nullptr)) {DRAWING_LOGE("OnSurfaceCreatedCB: component or window is null");return;}char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {'\0'};uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;if (OH_NativeXComponent_GetXComponentId(component, idStr, &idSize) != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {DRAWING_LOGE("OnSurfaceCreatedCB: Unable to get XComponent id");return;}std::string id(idStr);auto render = MinuteView::GetInstance(id);OHNativeWindow *nativeWindow = static_cast<OHNativeWindow *>(window);render->SetNativeWindow(nativeWindow);uint64_t width;uint64_t height;int32_t xSize = OH_NativeXComponent_GetXComponentSize(component, window, &width, &height);if ((xSize == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) && (render != nullptr)) {render->SetHeight(height);render->SetWidth(width);}
}
5.导出Native函数
void MinuteView::Export(napi_env env, napi_value exports) {if ((env == nullptr) || (exports == nullptr)) {DRAWING_LOGE("Export: env or exports is null");return;}napi_property_descriptor desc[] = {{"draw", nullptr, MinuteView::NapiDraw, nullptr, nullptr, nullptr, napi_default, nullptr}};napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);if (napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc) != napi_ok) {DRAWING_LOGE("Export: napi_define_properties failed");}
}
6.在NapiDraw中绘制分时图
  • 1.读取arkts侧透传过来的数据
vector<HuMarketMinuteData *> myVector;size_t argc = 3;napi_value args[3] = {nullptr};napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);napi_value vec = args[0];    // vectornapi_value vecNum = args[1]; // lengthuint32_t vecCNum = 0;napi_get_value_uint32(env, vecNum, &vecCNum);for (uint32_t i = 0; i < vecCNum; i++) {napi_value vecData;napi_get_element(env, vec, i, &vecData);HuMarketMinuteData *minuteData = new HuMarketMinuteData(&env, vecData);myVector.push_back(minuteData);}
#include "HuMarketMinuteData.h"
#include "common/MinuteItem.h"
#include "napi/native_api.h"
HuMarketMinuteData::HuMarketMinuteData(napi_env *env, napi_value value) {napi_value api_date, api_isDateChanged, api_yclosePrice, api_minuteItems;napi_get_named_property(*env, value, "date", &api_date);napi_get_named_property(*env, value, "isDateChanged", &api_isDateChanged);napi_get_named_property(*env, value, "yClosePrice", &api_yclosePrice);napi_get_named_property(*env, value, "minuteList", &api_minuteItems);uint32_t *uint32_date;napi_get_value_uint32(*env, api_date, uint32_date);date = int(*uint32_date);napi_get_value_double(*env, api_yclosePrice, &yClosePrice);uint32_t length;napi_get_array_length(*env, api_minuteItems, &length);for (uint32_t i = 0; i < length; i++) {napi_value api_minuteItem;napi_get_element(*env, api_minuteItems, i, &api_minuteItem);MinuteItem *minuteItem = new MinuteItem(env, api_minuteItem);minuteList.push_back(minuteItem);}
}
HuMarketMinuteData::~HuMarketMinuteData() {for (MinuteItem *item : minuteList) {delete item;item = nullptr;}
}
  • 2.绘制分时图
void MinuteView::Drawing2(vector<HuMarketMinuteData *>& minuteDatas) {if (nativeWindow_ == nullptr) {DRAWING_LOGE("nativeWindow_ is nullptr");return;}int ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow_, &buffer_, &fenceFd_);DRAWING_LOGI("request buffer ret = %{public}d", ret);bufferHandle_ = OH_NativeWindow_GetBufferHandleFromNative(buffer_);mappedAddr_ = static_cast<uint32_t *>(mmap(bufferHandle_->virAddr, bufferHandle_->size, PROT_READ | PROT_WRITE, MAP_SHARED, bufferHandle_->fd, 0));if (mappedAddr_ == MAP_FAILED) {DRAWING_LOGE("mmap failed");}// 创建一个bitmap对象cBitmap_ = OH_Drawing_BitmapCreate();// 定义bitmap的像素格式OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};// 构造对应格式的bitmap,width的值必须为 bufferHandle->stride / 4OH_Drawing_BitmapBuild(cBitmap_, width_, height_, &cFormat);// 创建一个canvas对象cCanvas_ = OH_Drawing_CanvasCreate();// 将画布与bitmap绑定,画布画的内容会输出到绑定的bitmap内存中OH_Drawing_CanvasBind(cCanvas_, cBitmap_);// 清除画布内容OH_Drawing_CanvasClear(cCanvas_, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));float padding = 30, with = width_, height = height_ / 2;float ltX = padding, ltY = 1, rtX = with - padding,rtY = 1,lbX = padding,lbY = height - 1,rbX = with - padding,rbY = height - 1;// 创建一个path对象cPath_ = OH_Drawing_PathCreate();// 指定path的起始位置OH_Drawing_PathMoveTo(cPath_, ltX, ltY);// 用直线连接到目标点OH_Drawing_PathLineTo(cPath_, rtX, rtY);OH_Drawing_PathLineTo(cPath_, rbX, rbY);OH_Drawing_PathLineTo(cPath_, lbX, lbY);// 闭合形状,path绘制完毕OH_Drawing_PathClose(cPath_);OH_Drawing_PathMoveTo(cPath_, padding, height / 2);OH_Drawing_PathLineTo(cPath_, with - padding, height / 2);OH_Drawing_PathMoveTo(cPath_, with / 2, 1);OH_Drawing_PathLineTo(cPath_, with / 2, height - 1);// 创建一个画笔Pen对象,Pen对象用于形状的边框线绘制cPen_ = OH_Drawing_PenCreate();OH_Drawing_PenSetAntiAlias(cPen_, true);OH_Drawing_PenSetColor(cPen_, OH_Drawing_ColorSetArgb(0xFF, 0xE6, 0xE6, 0xE6));OH_Drawing_PenSetWidth(cPen_, 2.0);OH_Drawing_PenSetJoin(cPen_, LINE_ROUND_JOIN);// 将Pen画笔设置到canvas中OH_Drawing_CanvasAttachPen(cCanvas_, cPen_);OH_Drawing_CanvasDrawPath(cCanvas_, cPath_);double minPrice, maxPrice;computeMaxMin(minuteDatas, &minPrice, &maxPrice);OH_Drawing_Path *pricePath_ = OH_Drawing_PathCreate();OH_Drawing_Path *avgPath_ = OH_Drawing_PathCreate();// 指定path的起始位置HuMarketMinuteData *minuteData = minuteDatas[0];// 单位长度float unitHeight = height / (maxPrice - minPrice);float itemWidth = (with - 2 * padding) / (240 * minuteDatas.size());float pointX = padding;float pointY = 0;float avg_pointX = padding;float avg_pointY = 0;bool isFirst = true;float yClosePrice = 0;for (int i = 0; i < minuteDatas.size(); i++) {HuMarketMinuteData *minuteData = minuteDatas[i];if (i == 0) {yClosePrice = minuteData->yClosePrice;}if (minuteData != nullptr) {for (int j = 0; j < minuteData->minuteList.size(); j++) {MinuteItem *minuteItem = minuteData->minuteList[j];if (minuteItem != nullptr) {pointY = (maxPrice - minuteItem->nowPrice) * unitHeight;avg_pointY = (maxPrice - minuteItem->avgPrice) * unitHeight;if (isFirst) {isFirst = false;OH_Drawing_PathMoveTo(pricePath_, pointX, pointY);OH_Drawing_PathMoveTo(avgPath_, avg_pointX, avg_pointY);} else {OH_Drawing_PathLineTo(pricePath_, pointX, pointY);OH_Drawing_PathLineTo(avgPath_, avg_pointX, avg_pointY);}pointX += itemWidth;avg_pointX += itemWidth;}}}}// 创建一个画笔Pen对象,Pen对象用于形状的边框线绘制cPen_ = OH_Drawing_PenCreate();OH_Drawing_PenSetAntiAlias(cPen_, true);OH_Drawing_PenSetColor(cPen_, OH_Drawing_ColorSetArgb(0xFF, 0x22, 0x77, 0xcc));OH_Drawing_PenSetWidth(cPen_, 5.0);OH_Drawing_PenSetJoin(cPen_, LINE_ROUND_JOIN);// 将Pen画笔设置到canvas中OH_Drawing_CanvasAttachPen(cCanvas_, cPen_);// 在画布上画PriceOH_Drawing_CanvasDrawPath(cCanvas_, pricePath_);OH_Drawing_PenSetColor(cPen_, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x9D, 0x03));OH_Drawing_CanvasAttachPen(cCanvas_, cPen_);OH_Drawing_CanvasDrawPath(cCanvas_, avgPath_);OH_Drawing_PathLineTo(pricePath_, pointX, height);OH_Drawing_PathLineTo(pricePath_, padding, height);OH_Drawing_PathClose(pricePath_);OH_Drawing_CanvasDrawShadow(cCanvas_, pricePath_, {5, 5, 5}, {15, 15, 15}, 30,OH_Drawing_ColorSetArgb(0x00, 0xFF, 0xff, 0xff),OH_Drawing_ColorSetArgb(0x33, 0x22, 0x77, 0xcc), SHADOW_FLAGS_TRANSPARENT_OCCLUDER);// 选择从左到右/左对齐等排版属性OH_Drawing_TypographyStyle *typoStyle = OH_Drawing_CreateTypographyStyle();OH_Drawing_SetTypographyTextDirection(typoStyle, TEXT_DIRECTION_LTR);OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_LEFT);// 设置文字颜色,例如黑色OH_Drawing_TextStyle *txtStyle = OH_Drawing_CreateTextStyle();OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x9D, 0x03));// 设置文字大小、字重等属性double fontSize = width_ / 15;OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_ALPHABETIC);OH_Drawing_SetTextStyleFontHeight(txtStyle, 1);// 如果需要多次测量,建议fontCollection作为全局变量使用,可以显著减少内存占用OH_Drawing_FontCollection *fontCollection = OH_Drawing_CreateSharedFontCollection();// 注册自定义字体const char *fontFamily = "myFamilyName"; // myFamilyName为自定义字体的family nameconst char *fontPath = "/data/storage/el2/base/haps/entry/files/myFontFile.ttf"; // 设置自定义字体所在的沙箱路径OH_Drawing_RegisterFont(fontCollection, fontFamily, fontPath);// 设置系统字体类型const char *systemFontFamilies[] = {"Roboto"};OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, systemFontFamilies);OH_Drawing_SetTextStyleFontStyle(txtStyle, FONT_STYLE_NORMAL);OH_Drawing_SetTextStyleLocale(txtStyle, "en");// 设置自定义字体类型auto txtStyle2 = OH_Drawing_CreateTextStyle();OH_Drawing_SetTextStyleFontSize(txtStyle2, fontSize);const char *myFontFamilies[] = {"myFamilyName"}; // 如果已经注册自定义字体,填入自定义字体的family// name使用自定义字体OH_Drawing_SetTextStyleFontFamilies(txtStyle2, 1, myFontFamilies);OH_Drawing_TypographyCreate *handler = OH_Drawing_CreateTypographyHandler(typoStyle, fontCollection);OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle2);// 设置文字内容const char *text = doubleToStringWithPrecision(yClosePrice, 2).c_str();OH_Drawing_TypographyHandlerAddText(handler, text);OH_Drawing_TypographyHandlerPopTextStyle(handler);OH_Drawing_Typography *typography = OH_Drawing_CreateTypography(handler);// 设置页面最大宽度double maxWidth = width_;OH_Drawing_TypographyLayout(typography, maxWidth);// 设置文本在画布上绘制的起始位置double position[2] = {100, height / 2.0};// 将文本绘制到画布上OH_Drawing_TypographyPaint(typography, cCanvas_, position[0], position[1]);void *bitmapAddr = OH_Drawing_BitmapGetPixels(cBitmap_);uint32_t *value = static_cast<uint32_t *>(bitmapAddr);uint32_t *pixel = static_cast<uint32_t *>(mappedAddr_);if (pixel == nullptr) {DRAWING_LOGE("pixel is null");return;}if (value == nullptr) {DRAWING_LOGE("value is null");return;}for (uint32_t x = 0; x < width_; x++) {for (uint32_t y = 0; y < height_; y++) {*pixel++ = *value++;}}Region region{nullptr, 0};OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow_, buffer_, fenceFd_, region);int result = munmap(mappedAddr_, bufferHandle_->size);if (result == -1) {DRAWING_LOGE("munmap failed!");}
}

绘制流程:

  • 向OHNativeWindow申请一块buffer, 并获取这块buffer的handle,然后映射内存;
  • 创建画布Canvas, 将bitmap和画布绑定;
  • 使用Canvas相关api绘制内容;
  • 将bitmap转换成像素数据,并通过之前映射的buffer句柄,将bitmap数据写到buffer中;
  • 将内容放回到Buffer队列,在下次Vsync信号就会将buffer中的内容绘制到屏幕上;
  • 取消映射内存;
7.ArkTS侧使用XComponent
  • 添加so依赖
  "devDependencies": {"@types/libnativerender.so": "file:./src/main/cpp/types/libnativerender"}
  • 定义native接口
export default interface XComponentContext {draw(minuteData: UPMarketMinuteData[], length: number): void;
};
  • 使用XComponent并获取XComponentContext, 通过它可以调用native层函数
      XComponent({id: 'xcomponentId',type: 'surface',libraryname: 'nativerender'}).onLoad((xComponentContext) => {if (xComponentContext) {this.xComponentContext = xComponentContext as XComponentContext;}}).width('100%').height(600).backgroundColor(Color.Gray)
  • 调用native函数绘制分时图
    this.monitor.subscribeRTMinuteData(this.TAG_REQUEST_MINUTE, param, (rsp) => {if (rsp.isSuccessful() && rsp.result != null && rsp.result.length > 0 && this.xComponentContext) {this.xComponentContext.draw(rsp.result!, rsp.result.length)}})

在这里插入图片描述

相关文章:

HarmonyOS Next开发----使用XComponent自定义绘制

XComponent组件作为一种绘制组件&#xff0c;通常用于满足用户复杂的自定义绘制需求&#xff0c;其主要有两种类型"surface和component。对于surface类型可以将相关数据传入XComponent单独拥有的NativeWindow来渲染画面。 由于上层UI是采用arkTS开发&#xff0c;那么想要…...

什么是电商云手机?可以用来干什么?

随着电商行业的迅速发展&#xff0c;云手机作为一种创新工具正逐渐进入出海电商领域。专为外贸市场量身定制的出海电商云手机&#xff0c;已经成为许多外贸企业和出海电商卖家的必备。本文将详细介绍电商云手机是什么以及可以用来做什么。 与国内云手机偏向于游戏场景不同&…...

Python 2 和 Python 3的差异

Python 2 和 Python 3 之间有许多差异&#xff0c;Python 3 是 Python 语言的更新版本&#xff0c;目的是解决 Python 2 中的一些设计缺陷&#xff0c;并引入更现代的编程方式。以下是 Python 2 和 Python 3 之间的一些主要区别&#xff1a; 文章目录 1. print 语句2. 整除行为…...

Leetcode 第 139 场双周赛题解

Leetcode 第 139 场双周赛题解 Leetcode 第 139 场双周赛题解题目1&#xff1a;3285. 找到稳定山的下标思路代码复杂度分析 题目2&#xff1a;3286. 穿越网格图的安全路径思路代码复杂度分析 题目3&#xff1a;3287. 求出数组中最大序列值思路代码复杂度分析 题目4&#xff1a;…...

spring 注解 - @NotEmpty - 确保被注解的字段不为空,而且也不是空白(即不是空字符串、不是只包含空格的字符串)

NotEmpty 是 Bean Validation API 提供的注解之一&#xff0c;用于确保被注解的字段不为空。它检查字符串不仅不是 null&#xff0c;而且也不是空白&#xff08;即不是空字符串、不是只包含空格的字符串&#xff09;。 这个注解通常用在 Java 应用程序中&#xff0c;特别是在处…...

深入理解华为仓颉语言的数值类型

解锁Python编程的无限可能&#xff1a;《奇妙的Python》带你漫游代码世界 在编程过程中&#xff0c;数据处理是开发者必须掌握的基本技能之一。无论是开发应用程序还是进行算法设计&#xff0c;了解不同数据类型的特性和用途都至关重要。本文将深入探讨华为仓颉语言中的基本数…...

WPF 的TreeView的TreeViewItem下动态生成TreeViewItem

树形结构仅部分需要动态生成TreeViewItem的可以参考本文。 xaml页面 <TreeView MinWidth"220" ><TreeViewItem Header"功能列表" ItemsSource"{Binding Functions}"><TreeViewItem.ItemTemplate><HierarchicalDataTempla…...

使用Go语言的互斥锁(Mutex)解决并发问题

解锁Python编程的无限可能:《奇妙的Python》带你漫游代码世界 在并发编程中,由于存在竞争条件和数据竞争,我们需要将某些代码片段设定为临界区,并使用互斥锁(Mutex)等同步原语来保护这些临界区。本文将详细介绍Go语言标准库中Mutex的使用方法,以及如何利用它来解决实际…...

Android平台Unity3D下如何同时播放多路RTMP|RTSP流?

技术背景 好多开发者&#xff0c;提到希望在Unity的Android头显终端&#xff0c;播放2路以上RTMP或RTSP流&#xff0c;在设备性能一般的情况下&#xff0c;对Unity下的RTMP|RTSP播放器提出了更高的要求。实际上&#xff0c;我们在前几年发布Unity下直播播放模块的时候&#xf…...

网络:TCP协议-报头字段

个人主页 &#xff1a; 个人主页 个人专栏 &#xff1a; 《数据结构》 《C语言》《C》《Linux》《网络》 文章目录 前言一、TCP协议格式16位源端口号 和 16位目的端口号4位首部长度16位窗口大小32位序号 和 32位确认序号6种标记位 和 16位紧急指针 总结 前言 本文是我对于TCP协…...

JAVA基础:HashMap底层数组容量控制,TreeMap底层存取机制,位运算符,原码反码补码

List常用实现类 List集合常用的实现类有3个 &#xff0c; ArrayList , LinkedList , Vector ArrayList 类似于我们之前的ArrayBox 底层使用数组存储元素&#xff0c; 插入删除的效率低&#xff0c;检索的效率高 当底层数组存储容量不足时&#xff0c;会进行扩容&#xff0c;…...

【Redis】Redis 缓存设计:抗住百万并发量的最佳实践

目录 1. Redis 缓存设计原则1.1 高可用性1.2 数据一致性1.3 读写分离 2. 缓存策略2.1 常用缓存策略2.1.1 缓存穿透2.1.2 缓存雪崩2.1.3 缓存击穿 2.2 额外缓存策略2.2.1 更新策略2.2.2 预热策略2.2.3 侧写缓存 3. Redis 架构设计3.1 单机 vs 集群3.2 Redis 集群示例架构 4. 性能…...

【hot100-java】【缺失的第一个正数】

R9-普通数组篇 class Solution {public int firstMissingPositive(int[] nums) {int nnums.length;for (int i0;i<n;i){while(nums[i]>0&&nums[i]<n&&nums[nums[i]-1]!nums[i]){//交换nums[i]和nums[nums[i]-1]int temp nums[nums[i]-1];nums[nums[i]…...

独立站新手教程转化篇:如何做好移动端优化?

随着移动设备在全球范围内的普及&#xff0c;越来越多消费者选择通过手机或平板电脑&#xff0c;来进行线上购物。因此移动端优化&#xff0c;因此移动端优化&#xff0c;也成为独立站卖家必须重视的一个关键环节。那么独立站移动端需要做好哪些优化工作呢&#xff1f; 选择响…...

Mybatis Plus分页查询返回total为0问题

Mybatis Plus分页查询返回total为0问题 一日&#xff0c;乌云密布&#xff0c;本人看着mybatis plus的官方文档&#xff0c;随手写了个分页查询&#xff0c;如下 Page<Question> questionPage questionService.page(new Page<>(current, size),questionService.g…...

VulnHub-Narak靶机笔记

Narak靶机笔记 概述 Narak是一台Vulnhub的靶机&#xff0c;其中有简单的tftp和webdav的利用&#xff0c;以及motd文件的一些知识 靶机地址&#xff1a; https://pan.baidu.com/s/1PbPrGJQHxsvGYrAN1k1New?pwda7kv 提取码: a7kv 当然你也可以去Vulnhub官网下载 一、nmap扫…...

查看和升级pytorch到指定版本

文章目录 查看和升级pytorch到指定版本查看pytorch的版本python 命令查看pytorch的版本使用pip 命令查看当前安装的PyTorch版本升级PyTorch到指定版本 升级到特定的版本 查看和升级pytorch到指定版本 查看pytorch的版本 python 命令查看pytorch的版本 通过Python的包管理工具…...

Maya---机械模型制作

材质效果&#xff08;4&#xff09;_哔哩哔哩_bilibili 三角面 四边面 多边面 *游戏允许出现三角面和四边面 游戏中一般是低模&#xff08;几千个面&#xff09; 动漫及影视是高模 机械由单独零件组合而成&#xff0c;需独立制作 低面模型到高面模型 卡线是为了将模型保…...

请不要在TS中使用Function类型

在 TypeScript 中&#xff0c;避免使用 Function 作为类型。Function 代表的是“任意类型的函数”&#xff0c;这会带来类型安全问题。对于绝大多数情况&#xff0c;你可能更希望明确地指定函数的参数和返回值类型。 如果你确实想表达一个可以接收任意数量参数并返回任意类型的…...

关于UVM仿真error数量达到指定值就退出仿真的设置

1. 问题描述 在某项目调试过程中&#xff0c;发现通过tc_base.sv中new函数里的set_report_max_quit_count()设置最大error数量不生效&#xff0c;uvm_error数量仍旧是达到10个&#xff08;默认&#xff09;就会退出仿真。 2. 设置uvm_error到达一定数量结束仿真的方式 由白皮…...

chatGPT问答知识合集【二】

Redis 架构说明 Redis 是一个开源的内存数据库&#xff0c;它也可以持久化到磁盘。以下是 Redis 的典型架构说明&#xff1a;### Redis 架构组件&#xff1a;1. **客户端**&#xff1a;与 Redis 服务器进行通信的应用程序或客户端库。2. **Redis 服务器**&#xff1a;执行实际…...

不靠学历,不拼年资,怎么才能月入2W?

之前统计局发布了《2023年城镇单位就业人员年平均工资情况》&#xff0c;2023年全国城镇非私营单位和私营单位就业人员年平均工资分别为120698元和68340元。也就是说在去年非私营单位就业人员平均月薪1W&#xff0c;而私营单位就业人员平均月薪只有5.7K左右。 图源&#xff1a;…...

【软考】多核CPU

目录 1. 说明 1. 说明 1.核心又称为内核&#xff0c;是 CPU 最重要的组成部分。2.CPU 中心那块隆起的芯片就是核心&#xff0c;是由单品硅以一定的生产工艺制造出来的&#xff0c;CPU 所有的计算、接收/存储命令、处理数据都由核心执行。3.各种 CPU 核心都具有固定的逻辑结构&…...

制作炫酷个人网页:用 HTML 和 CSS3 展现你的风格

你是否觉得自己的网站应该看起来更炫酷&#xff1f;今天我将教你如何使用 HTML 和 CSS3 制作一个拥有炫酷动画和现代设计风格的个人网页&#xff0c;让它在任何设备上看起来都无敌酷炫&#xff01; 哈哈哈哈哈哈哈哈,我感觉自己有点中二哈哈哈哈~ 目录 炫酷设计理念构建 HTML …...

WinCC中归档数据片段的时间和尺寸设置

1&#xff0e;归档数据片段介绍工控人加入PLC工业自动化精英社群 1.1 概述 WinCC V6.2 开始的后台数据库采用了MS SQL Server 2005 &#xff0c;所以归档方式与V5 有所不同&#xff0c;它的运行数据存放在数据片段&#xff08;segment&#xff09;当中&#xff0c;工程师可以…...

kubernetes网络(二)之bird实现节点间BGP互联的实验

摘要 上一篇文章中我们学习了calico的原理&#xff0c;kubernetes中的node节点&#xff0c;利用 calico 的 bird 程序相互学习路由&#xff0c;为了加深对 bird 程序的认识&#xff0c;本文我们将使用bird进行实验&#xff0c;实验中实现了BGP FULL MESH模式让宿主相互学习到对…...

动态语言? 静态语言? ------区别何在?java,js,c,c++,python分给是静态or动态语言?

JavaScript 被称为动态语言&#xff0c;而 Java 被称为静态语言 这主要与它们在类型系统、编译执行方式以及运行时行为等方面的不同特性有关。详细差异如下&#xff1a; JavaScript (动态语言) 动态类型&#xff1a; 在JavaScript中&#xff0c;变量的类型是在运行时确定的。这…...

计算机网络17——IM聊天系统——客户端核心处理类框架搭建

目的 拆开客户端和服务端&#xff0c;使用Qt实现客户端&#xff0c;VS实现服务端 Qt创建项目 Qt文件类型 .pro文件&#xff1a;配置文件&#xff0c;决定了哪些文件参与编译&#xff0c;怎样参与编译 .h .cpp .ui&#xff1a;画图文件 Qt编码方式 Qt使用utf-8作为编码方…...

C/C++面试题

关键字 1."#"&#xff0c;"##"的用法 #是字符串转换符&#xff0c;##是字符串连接符&#xff1b;发生在预处理阶段&#xff1b; 2.volatile的含义 防止编译器优化&#xff0c;告诉编译器每次都去真实地址中读取&#xff0c;而不是从寄存器或者缓存中&a…...

[3]Opengl ES着色器

术语&#xff1a; VertexShader&#xff1a;顶点着色器&#xff0c;用来描述图形图像位置的顶点坐标&#xff1b; FragmentShader&#xff1a;片元着色器&#xff0c;用来给顶点指定的区域进行着色&#xff1b; Vertex&#xff1a;顶点 Texture&#xff1a;纹理…...