private int getMaxElementsThatFit(Program program, Address addr, int elementSize) {

		// can't go past the end of a block to start with
		MemoryBlock block = program.getMemory().getBlock(addr);
		if (block == null) {
			return 0;
		}

		Address maxAddr = block.getEnd();

		// get the next non undefined element in memory
		Instruction instr = program.getListing().getInstructionAfter(addr);
		if (instr != null) {
			Address instrAddr = instr.getMinAddress();
			if (instrAddr.compareTo(maxAddr) < 0) {
				maxAddr = instrAddr.subtract(1);
			}
		}

		// get the next non undefined data element in memory
		Data data = DataUtilities.getNextNonUndefinedDataAfter(program, addr, maxAddr);
		if (data != null) {
			Address dataAddr = data.getMinAddress();
			if (dataAddr.compareTo(maxAddr) < 0) {
				maxAddr = dataAddr.subtract(1);
			}
		}

		int length = (int) maxAddr.subtract(addr) + 1;
		if (length < 0) {
			return 0;
		}
		return (length / elementSize);
	}
Get the maximum number of elements that will fit.  This means the undefined
bytes available up to the next instruction or defined data.

NOTE: right now this does not include holes in memory, or looking for the
end of memory.  The protoBuf would need to be changed to find the end of the
current memory block and restrict the length to that.

@return the maximum number of elements for an array of the given data type
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/data/CreateArrayAction.java