FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LC_baseTools/resizeBuff.cpp at master · leftCoast/LC_baseTools · GitHub
leftCoast
/
LC_baseTools
Public
Notifications
You must be signed in to change notification settings
Fork
10
Star
24
Code
Issues
1
Pull requests
0
Actions
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
LC_baseTools
/
resizeBuff.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
72 lines (49 loc) · 2.95 KB
Breadcrumbs
LC_baseTools
/
resizeBuff.cpp
Copy path
File metadata and controls
72 lines (49 loc) · 2.95 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#
include
<
resizeBuff.h
>
//
#include <debug.h>
//
****************************************************************************************
//
****************************************************************************************
//
//
DON'T USE UNINITIALIZED POINTERS!! EVEN JUST SETTING TO NULL WILL BE FINE.
//
//
Once your pointer is either set to NULL or allocated, then it can be used in here all
//
you want.
//
****************************************************************************************
//
****************************************************************************************
//
****************************************************************************************
//
resizeBuff:
//
****************************************************************************************
bool
resizeBuff
(
int
numBytes,
uint8_t
** buff) {
if
(*buff) {
//
If we did NOT get passed in a NULL..
free
(*buff);
//
We free the memory.
*buff =
NULL
;
//
Set the pointer to NULL.
}
//
if
(numBytes>
0
) {
//
If we got a positive non zero value..
*buff = (
uint8_t
*)
malloc
(numBytes);
//
We attempt allocate that number of bytes.
if
(*buff==
NULL
) {
//
Serial.print("resizeBuff fail : ");
//
Serial.println(numBytes);
}
return
*buff !=
NULL
;
//
And we return true for non NULL result (non-NULL = Success)
}
//
return
true
;
//
In this case we were not asked to allocate anything so it was a success.
}
bool
resizeBuff
(
int
numBytes,
char
** buff) {
return
resizeBuff
(numBytes,(
uint8_t
**)buff); }
bool
resizeBuff
(
int
numBytes,
void
** buff) {
return
resizeBuff
(numBytes,(
uint8_t
**)buff); }
bool
resizeBuff
(
int
numBytes,
float
** buff) {
return
resizeBuff
(numBytes,(
uint8_t
**)buff); }
//
****************************************************************************************
//
maxBuff:
//
//
Class for slicing up huge data streams into bite sized buffers. Good for things like
//
copying one file to another.
//
****************************************************************************************
maxBuff::maxBuff
(
unsigned
long
numBytes,
unsigned
long
minBytes) {
theBuff =
NULL
;
//
Pointers start at NULL.
numBuffBytes = numBytes;
//
In a perfect world, numBytes will work.
numPasses =
1
;
//
In that same world, we'll only need one pass.
while
(!
resizeBuff
(numBuffBytes,&theBuff)) {
//
Have a go at allocating the buffer..
numPasses++;
//
If we didn't get it, bump up number of passes.
numBuffBytes = (numBytes/numPasses) +
1
;
//
Cut down the buffer size.
if
(numBuffBytes<minBytes)
return
;
//
At some point, lets just give up.
}
//
If we didn't get it last time, we try again smaller.
}
maxBuff::~maxBuff
(
void
) {
resizeBuff
(
0
,&theBuff); }
Back
|
FazBrowse Home
|
New Git URL